Reputation: 1407
I'm trying to have a constructor call other constructors in their initialization list for I don't have duplicate logic. Here is what my .h file looks like:
class Button : public Component
{
public:
Button(int x, int y, int width, int height, string normalSrc, string hoverSrc, string downSrc);
Button(int x, int y, int width, int height, string normalSrc, string hoverSrc, string downSrc, Uint8 r, Uint8 g, Uint8 b);
Button(int x, int y, int width, int height, string src) : Button(x, y, width, height, src, src, src) { }
Button(int x, int y, int width, int height, string src, Uint8 r, Uint8 g, Uint8 b) : Button(x, y, width, height, src, src, src, r, g, b) { }
~Button();
but when I try to compile (using -std=c++0x as an extra compiler flag) I get this error:
In file included from /home/villages/Desktop/ogam-january-pipes/src/Vesper/Ui/Button.cpp:8:0:
/home/villages/Desktop/ogam-january-pipes/src/Vesper/Ui/Button.h: In constructor ‘Button::Button(int, int, int, int, std::string)’:
/home/villages/Desktop/ogam-january-pipes/src/Vesper/Ui/Button.h:29:60: error: type ‘Button’ is not a direct base of ‘Button’
/home/villages/Desktop/ogam-january-pipes/src/Vesper/Ui/Button.h: In constructor ‘Button::Button(int, int, int, int, std::string, Uint8, Uint8, Uint8)’:
/home/villages/Desktop/ogam-january-pipes/src/Vesper/Ui/Button.h:30:87: error: type ‘Button’ is not a direct base of ‘Button’
make[2]: *** [CMakeFiles/Villages.dir/src/Vesper/Ui/Button.cpp.o] Error 1
make[1]: *** [CMakeFiles/Villages.dir/all] Error 2
make: *** [all] Error 2
What am I doing wrong?
Thanks!
Upvotes: 1
Views: 242
Reputation: 81409
What am I doing wrong?
You are using the wrong compiler/version. The delegating constructors feature is a C++11 feature, and not all compilers have caught up yet.
According to this table GCC supports it since 4.7, Clang since 3.0, and MSVC since Nov 2012 CTP.
Upvotes: 5