Sign in to follow this  
baker

undeclared identifier, WHAT?! doubled, tripled, 100led checked my includes!

Recommended Posts

baker    158
first question, what does this syntax do? basically the right part of the ':'?is it a contructor calling another contructor of another class? //someFile.cpp myMenuHandlerBase::myMenuHandlerBase(myControl *inControl, int menuID):someHandlerBase(inControl, inID) { blah.... } ///////////////////////////////////////////////////////// second problem is that the function on top cant seem to recognize class 'myControl'. the compiler says "myControl' : undeclared identifier" now i must of checked the headers about 100 times to make sure myControl.hpp is included in my file. i also made sure i didnt do any multiple includes that might throw it off. i also changed around what was in the myControl.hpp to make sure that the errors i put in, would get picked up when i compile the file above. so, have you ever encountered a problem like mine where you have the INCLUDE, the compiler SEES the INCLUDE, but still states that it has a "UNDECLARED IDENTIFIER"?!!!

Share this post


Link to post
Share on other sites
Yes, that calls the someHandlerBase() constructor before calling the derived class' constructor. As for your include error, we need to see the .hpp file and how it's being included in the .cpp file; we can't help you otherwise.

Share this post


Link to post
Share on other sites
Talonius    643
Quote:
Original post by baker
hi, thanks for the reply. but what would be the 2 most basic reasons why someone would do that?


Delegation.

If you're inheriting from an object you only know part of what goes on inside the object. By delegating a portion of the construction of the object to the base class you ensure 1) that the object is assembled properly as far as the base class is concerned; and 2) you avoid having to rewrite code which would be identical to the original code.

Share this post


Link to post
Share on other sites
Fruny    1658
Quote:
Original post by baker
hi, thanks for the reply. but what would be the 2 most basic reasons why someone would do that?


Necessity and Efficiency.








Yes, really.






If the base class doesn't define a default constructor but has some other user-defined constructor then it is not default-constructible (duh). That means that when you create an object of a derived class you need to specify which parameters to pass to the base class constructor. That's Necessity.

Secondly, even if you could default-construct the class, it would be wasteful to do so and then throw away the work you have done in initializing the base class members by reassigning them with new values. It's much better to directly construct them with their proper values. That's Efficiency.

Note that constructor initialization lists also work for member variables (in fact, that's their most common use). In most cases where you find yourself writing:

class Foo
{
Bar bar;
public:
Foo(Bar b) { bar = b }
};


you should instead write

class Foo
{
Bar bar;
public:
Foo(Bar b) : bar(b) {}
};


The argument about non default-constructible base classes also applies to member variables, which can then only be initialized this way.

Share this post


Link to post
Share on other sites
Quote:
Original post by baker
second problem is that the function on top cant seem to recognize class 'myControl'. the compiler says "myControl' : undeclared identifier"

now i must of checked the headers about 100 times to make sure myControl.hpp is included in my file. i also made sure i didnt do any multiple includes that might throw it off. i also changed around what was in the myControl.hpp to make sure that the errors i put in, would get picked up when i compile the file above.

so, have you ever encountered a problem like mine where you have the INCLUDE, the compiler SEES the INCLUDE, but still states that it has a "UNDECLARED IDENTIFIER"?!!!


Did you verified the header guards ? If you have header foo.h which is guarded by FOO_H and bar.h that is also guarded by FOO_H, you won't be able to see either the content of foo.h or the content of bar.h if you include both file. It really looks like you have the same kind of problem, so I'd check it first.

Regards,

Share this post


Link to post
Share on other sites
rip-off    10979
Try adding this to your header:


#ifdef ...
#define ...

#warning "successfully included x.h"

#endif



You may have to use #error, but it may tell you how far you've gotten...

Share this post


Link to post
Share on other sites
baker    158
well baker the noob just learned another NOOB lesson!


the header file of someHandlerBase.cpp contained a private member variable called "myControl *myControl".....!

this gave me the error of "myControl' : undeclared identifier". thinking stupidily that it has to do with that somehow it cant see the class, i kept checking header files. but reality was that the compiler viewed myControl as a variable and not a class!..geez...that killed alot of time but at least it wont happen again.


thanks all!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this