illogical compiler errors

Recommended Posts

Note: Using Visual Studio 6 When I include a class I wrote and try to implement it, the compiler generates errors C2146(missing identifier) and C2501(missing storage class). However, when I right click on the type and click, goto definition, the compiler finds it without trouble. In general I'm having trouble with the compiler locating definitions when they are blatently obvious. Any help/advice?

Share on other sites
The compiler errors are pretty logical, I assure you. But please post some code first [smile]

Share on other sites
Quote:
 Original post by adolNote: Using Visual Studio 6When I include a class I wrote and try to implement it, the compiler generates errors C2146(missing identifier) and C2501(missing storage class). However, when I right click on the type and click, goto definition, the compiler finds it without trouble. In general I'm having trouble with the compiler locating definitions when they are blatently obvious. Any help/advice?

The problem is when you right click on the type the 'IDE' finds it. Im not sure how the parsers for the IDE and compiler is connected but they may not nesseraly function the same and the compiler, when compiling, is actualy building the object files so i find it more strict. If i was to guess the IDE works out what type is what but using a diffrent system to the compiler.
(Just a guess though)

Share on other sites
Yup. The IDE scans all the files in your project. The compiler only scans the source file, and any headers in #include directives.
So basically, you're not including a header.

Share on other sites
This nasty little problem also crops up if there are circles in your includes.

a includes a,b
b includes a,b

then b tends not to find what it needs.

a inc a,b
b inc b,a

may find what it needs because the include order has changed.

took me days to track this down in one of my programs because the loop covered 20 or so source files.

Share on other sites
Kul Seran, your hypothesis of the problem is accurate, my program seems to be very circular inclusive. However, I tried to remedy the problem with the #ifndef/#define. How do I overcome this issue? Reorder the inclusion of the header files?

Share on other sites
If you class A only uses class B as paramteters in the member methods of clas A then you can forward declare class b like so: class B; at the top of your header file. You will need to include class B's header file in A's implementation file or you will get an error.

This method won't work if you have actual objects of B but this can be resolved by using pointers instead and allocating your B objects on the heap via new().

Share on other sites
If a class doesn't contain an actual object of another class it doesn't need its full definition, it can cope with knowing only the name.

//No Problemclass SomeOtherClass;//only need nameclass SomeClass {    SomeOtherClass* m_pSoc;    SomeOtherClass& m_refSoc;    void SomeFunction(SomeOtherClass);};

//Problemsclass SomeOtherClass;//only have nameclass SomeClass : public SomeOtherClass {//can't inherit without full definition    SomeOtherClass m_soc;//can't have member as need to know size of SomeOtherClass    void SomeFunction(SomeOtherClass soc) {        soc.hello();//can't use SomeOtherClass object    }};

Once you start making use of SomeOtherClass, i.e. calling functions, making use of its size etc, you'll have to have the full defintion (i.e. the header "SomeOtherClass.h").

Create an account

Register a new account

• Forum Statistics

• Total Topics
628383
• Total Posts
2982368

• 10
• 9
• 15
• 24
• 11