Delegating constructors: an initializer for a delegating constructor must appear alone
c++, c++11, constructor, delegation, superclass
Solution
The problem is that `Rectangle` is getting initialized twice.
You could try changing which one delegates to what:
Window(Rectangle _rect) : Rectangle(_rect), win(new RawWindow(*this))
{
refresh();
}
Window() : Window(Rectangle()) {}
The best solution is probably to avoid delegating constructors in this example.
Problem
I have a pair of constructors that work just fine in C++03 style. One of the constructors calls a superclass (or base class) constructor ... ``` class Window : public Rectangle { public: Window() : win(new RawWindow(*this)) { refresh(); } Window(Rectangle _rect) : Rectangle(_rect), win(new RawWindow(*this)) { refresh(); } ... ``` I am trying to figure out how to use the new C++11 delegating ctor functionality to neaten this up a little. However, the following code gives the following compiler error ... ``` class Window : public Rectangle { public: Window() : win(new RawWindow(*this)) { refresh(); } Window(Rectangle _rect) : Rectangle(_rect), Window(){} ``` "an initializer for a delegating constructor must appear alone" ... Is there any way around this??