views:

171

answers:

3

Hi, I'm trying to declare a method in main.h like this:

void buildGraph(int gNum, Graph** gArray);

Where Graph is a class and I'm trying to pass a pointer to an array of pointers to Graph objects.

I get the error message: "Graph has not been declared". Even though I have #include "graph.h" at the top of the page and I've been using the graph class plenty until now, so I know it works.

Any ideas?

+3  A: 

It's likely that you have more than one graph.h file in the filesystem and the wrong one is included. If it's because of accidential copying remove the unneeded copies, if it's because of collision with C++ standart library or other libraries headers you should rename you header files to prevent such collisions in future.

sharptooth
A: 

Maybe the name Graph is in a namespace? What does that graph.h file say -- is Graph at top-level, or inside a namespace statement?

Alex Martelli
my graph.h starts like this //#include "main.h"#include <stdio.h>#include <iostream>using namespace std;class Graph{private: int maxVal; Vlist vertList; Elist edgeList; public:Is that what you meant by being in namespace? Should I avoid using namespace like that? Does not using it mean that I have to use std:: before each standard function?Anyway, as I was copying the text to put here I noticed the problem was that I was including main.h in my graph.h file. Problem solved.Thanks!
Dave
Nope, here you make all the contents of the std:: visible without using the std:: prefix. Alex meant you could have smth like this: namespace MyNamespace { class Graph {}; };
sharptooth
I normally avoid "using namespace foo;" because it can get confusing for the reader or maintainer of the code, but, of all namespaces, std is the one that it can make sense to use this way.
Alex Martelli
+1  A: 

A common possibility for this is an incorrect include guard in Graph.h, possibly a left-over from another header file you are using.

That is, make sure the "#ifndef GRAPH_H"-like line you are supposed to have in Graph.h is really what it is supposed to be...

(but really, without more information answering this question is... hard).

Hexagon