我正在尝试让构造函数在其初始化列表中调用其他构造函数,因为我没有重复的逻辑。这是我的 .h 文件的样子:
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();
但是当我尝试编译时(使用 -std=c++0x 作为额外的编译器标志)我得到这个错误:
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
我究竟做错了什么?
谢谢!