Prev: calling this->~T() inside T::operator=3D
Next: Use c++ to draw a figure of a graph(data structure)
From: Tony Delroy on 12 Dec 2009 16:33 On Dec 13, 6:46 am, "Alf P. Steinbach" <al...(a)start.no> wrote: > * O.o: > > > This has been driving me completely bonkers for the past two days now, > > and I'm at my wit's end. Let's say I have a class Foo, which is > > defined in Foo.h and implemented in Foo.cpp. In another class, I want > > to instantiate a Foo object. Pretty simple. > > > #include "Foo.h" > > > int OtherClass::SomeFunction(void) > > { > > Foo foo; //C2065: 'Foo': undeclared identifier > > return 0; > > } > > > I'm six-trillion % certain that Foo.h and Foo.cpp are compiled. In > > fact, if when use the scope or member operator on 'Foo' or 'foo', > > Intellinonsense CORRECTLY LISTS ITS ACCESSIBLE MEMBERS!!!! What am I > > missing here?? > > See that FAQ item on how to post a question about Code That Does Not Work Correctly. > > Then repost. > > Cheers & hth., > > - Alf Exactly. Still, that said, the OP can check a couple things: - is Foo in a namespace? - has Foo.h got an #ifndef XYZ up the top? Make sure it doesn't say #ifdef by mistake. Look at the output of the preprocessing stage of your compiler (with most compilers, -E, but not sure about microsoft stuff) to check you're compiling what you think you should be. - break things down - see if you can use a Foo from a standalone test harness / int main () { Foo foo; } - if not, does it work if you move int main into the same source file This kind of simplification & rebuilding process is a crucial skill for development. Cheers, Tony -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Andrew on 14 Dec 2009 00:44 On 12 Dec, 21:46, Robert Hairgrove <rhairgr...(a)bigfoot.com> wrote: > O.o wrote: > > #include "Foo.h" > > > int OtherClass::SomeFunction(void) > > { > > Foo foo; //C2065: 'Foo': undeclared identifier > > return 0; > > } > > Without seeing any of the code in Foo.h, it is very hard to say. Indeed. But on hearing that you are using a Microsoft compiler something does spring to mind. The Microsoft compilers are very bad at handling headers that include themselves. Not that any header should of course. Still, these things happen. And when they do the Microsoft compiler tends to stop including at the point of a cycle and then trying to compile with what it has got. If this is happening with your headers then it may not have seen the definition of Foo in the header. This can be very puzzling initially. If you compiler with GCC it should give you a much better diagnostic if this is the problem. One very common way to minimise the chance of this occurring is to observe the rule "one class, one header". So Foo.h should just include the declaration for the class 'Foo'. If that decl needs other decls then Foo.h should include the headers that contain them. If Foo.h has decls for lots of classes then the header needs to be broken up into separate headers. Then if there are any cycles they will be a lot easier to see. Regards, Andrew Marlow -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
First
|
Prev
|
Pages: 1 2 Prev: calling this->~T() inside T::operator=3D Next: Use c++ to draw a figure of a graph(data structure) |