typedef not being seen

D

Dave

Hello all,

I have included below a header file for a module I'm working on. Please
note the line marked "***** ERROR HERE *****". At this line, the type dl_t
is not being seen for some reason. Can anybody see why this is?

Thanks,
Dave


#ifndef DIRECTED_GRAPH_INCLUDED
#define DIRECTED_GRAPH_INCLUDED

#include <algorithm>
#include <map>
#include <set>
#include <utility>
#include <vector>

namespace directed_graph
{
// Template parameter T specifies the type of the values used to uniquely
// identify vertices.
template<typename T>
class directed_graph_t
{
public:
directed_graph_t();

// The only way this can fail is if the source or destination does
not
// exist. A request to add an already-existing edge is a no-op.
In
// the event of a failure, an exception will be thrown containing
the
// offending vertex ID.
void add_edge(const T &source_id, const T &destination_id);

// This will never fail. A request to add an already-existing
vertex
// is a no-op.
void add_vertex(const T &vertex_id);

void clear();

// For each vertex, determine all vertices reachable from that
vertex.
dl_t get_descendents(); // ***** ERROR HERE *****

std::vector<T> get_dfs_discovery_times();
std::vector<T> get_dfs_finish_times();

bool is_acyclic();

// This function will return a topological sort of the vertex set,
if
// possible. The only case when this can't be done is if the graph
is
// not acyclic. In this case, an exception will be thrown.
std::vector<T> topological_sort();

private:
// Disable copying and assignment.
directed_graph_t(const directed_graph_t &);
directed_graph_t &operator=(const directed_graph_t &);

enum vertex_color_t
{
WHITE,
GRAY,
BLACK
};

// Types related to the adjacency list representation of a graph
typedef std::map<T, std::set<T> > al_t;
typedef typename al_t::iterator al_iter_t;

// Types related to descendents of vertices (i.e. other reachable
// vertices)
typedef std::map<T, std::set<T> > dl_t;
typedef typename dl_t::iterator dl_iter_t;

// Types used to store the colors of vertices
typedef std::map<T, vertex_color_t> vc_t;
typedef typename vc_t::iterator vc_iter_t;

bool acyclic;
al_t adjacency_list;
std::vector<T> dfs_discovery_times;
std::vector<T> dfs_finish_times;
bool dfs_search_performed;
vc_t vertex_colors;

void dfs_visit(const T &vertex_id);
void perform_dfs_search();
};
}

// Include the definition of functions declared above.
#include "directed_graph.inl"

#endif
 
G

Gianni Mariani

Dave said:
Hello all,

I have included below a header file for a module I'm working on. Please
note the line marked "***** ERROR HERE *****". At this line, the type dl_t
is not being seen for some reason. Can anybody see why this is?

dl_t is supposed to come from where ?
 
D

Dave

Gianni Mariani said:
dl_t is supposed to come from where ?

It's in the private section of the class definition. It's a typedef. It's
in there, but it's not necessarily easy to spot...

Oops, perhaps I just stumbled on something in answering you, but I still
don't think it solves my problem. Client code will need the type, so it
can't be private. But what I'm looking at now is *within( the class, so
that shouldn't matter. The private issue is a problem, but not *the*
problem I'm trying to track down now...
 
G

Gianni Mariani

Dave said:
It's in the private section of the class definition. It's a typedef. It's
in there, but it's not necessarily easy to spot...

Oops, perhaps I just stumbled on something in answering you, but I still
don't think it solves my problem. Client code will need the type, so it
can't be private. But what I'm looking at now is *within( the class, so
that shouldn't matter. The private issue is a problem, but not *the*
problem I'm trying to track down now...

I didn't find it because typedef dl_t has to come *before* it's used.

When I did that, it compiled fine.
 
D

Dave

I didn't find it because typedef dl_t has to come *before* it's used.
When I did that, it compiled fine.

OK, thanks. I clearly am missing some tidbits of knowledge on when a
declaration becomes visible. I always thought that anything in a class is
visibile anywhere in the class, even before it's declared. For example, the
program below is perfectly valid even though bar() calls something that
hasn't yet been seen at the point of the call. Nevertheless, I clearly have
some misconceptions. Could somebody please explain exactly what the rules
are with regard to visibility inside of a class for the different kinds of
entities that may be declared therein?

Thanks!

#include <iostream>

using namespace std;

class foo_t
{
public:
void bar() {impl();}

private:
void impl() {cout << "Got here!" << endl;}
};

int main()
{
foo_t f;

f.bar();
}
 
T

tom_usenet

OK, thanks. I clearly am missing some tidbits of knowledge on when a
declaration becomes visible. I always thought that anything in a class is
visibile anywhere in the class, even before it's declared. For example, the
program below is perfectly valid even though bar() calls something that
hasn't yet been seen at the point of the call. Nevertheless, I clearly have
some misconceptions. Could somebody please explain exactly what the rules
are with regard to visibility inside of a class for the different kinds of
entities that may be declared therein?

Name lookup inside member function definitions checks the whole class
scope. Name lookup in member declarations only checks class scope up
to that point.

Tom

C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,161
Latest member
GertrudeMa
Top