calling parent methods

For some reason I'm getting a compiler error when trying to call a method defined in a parent class from a child object. I keep getting:

error: request for member ` controller::CHUI::add_input' in `menu3', which is of non-class type `ScreenThreeCHUI ()()'

In one .hpp file I have a class called CHUI in a namespace called controller like this.
1
2
3
4
5
class CHUI {
public:
	void add_input();
};


I have a definition for add_input() below it.

Then in another .cpp where I have my main, I have an other class which is derived from it like this:

 
class ScreenThreeCHUI : public controller::CHUI{};


Then inside main I'm getting the compiler error when trying to do this.

1
2
ScreenThreeCHUI menu3();
menu3.add_input();


This has to be something simple, but I don't understand what would be wrong with trying to call add_input() which is a public method on CHUI from an object derived from CHUI.
Try this:
1
2
ScreenThreeCHUI menu3;
menu3.add_input();


Explanation, to follow:

The error message is telling you that line 2 above is treating menu3 as a ScreenThreeCHUI object, which it is not. It's baffling because you think that you declared it as an object of ScreenThreeCHUI. The parentheses cause the declaration on line 1 above to be parsed as a forward declaration for a function that returns a ScreenThreeCHUI and takes no parameters.

This is commonly referred to as "C++'s most vexing parse" as coined by Scott Meyers in his book, Effective C++.
Last edited on
Thank you. Yeah that's really really annoying.
Topic archived. No new replies allowed.