Inexplicable compiler error (VS '08)

O

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??
 
V

Vladimir Jovic

O.o said:
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??

Your example doesn't compile, but lets make a very wild guess : Foo.h
header and OtherClass.h headers have the same guards macro.
 
V

Victor Bazarov

O.o said:
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.

That's irrelevant, actually.
> 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??

Take the contents of the Foo.h file and stick them into that source
file, after commenting out the #include, save the file. Drop the 'void'
from between the parentheses. Save the file again. Quit the Visual
Studio app, then reboot your computer. Start Visual Studio again,
reopen the project. Do 'Build | Clean solution'. Then compile this
file again, see if anything is different.

Possible causes: (a) there is a macro you define that hides the entire
definition of 'Foo' from the compiler when you try compiling this file,
(b) Foo is actually defined in a namespace, and you just forgot about
it, (c) You got precompiled headers used and they need to be refreshed,
(d) Your computer is totally wack.

Also, see FAQ 5.8.

V
 
O

O.o

Your example doesn't compile, but lets make a very wild guess : Foo.h
header and OtherClass.h headers have the same guards macro.

D'Oh!!! Not quite, but excellent guess... The #include guard for Foo
was somehow was in the code file instead of the header. Er, oops!

But... why doesn't that burp out some sort of duplicate or ambiguous
definition error?

Anyway, thanks. I owe you my sanity.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top