Why can't one ctor call another ctor to initialize the object

c++

Solution

Because the language specification doesn't allow it. Just the way the language is. Very annoying if you're used to Java or other languages that allow it. However, you get used to it after a while. All languages have their quirks, this is just one of C++'s. I'm sure the writers of the specs have their reasons.

Best way around this I've found is to make a common initialization function and have both constructors call that.

Something like this:

class Foo {
public:
    Foo() {initialize(1);}
    Foo(int nX) { initialize(nx); }

private:
    void initialize(int nx) { x=nx; }
    int x;
};

Problem

``` class Foo { public: Foo() { Foo(1)} Foo(int x, int y = 0):i(x) {} private: int i; } ``` Can anybody give me some reasonas about can I do this? If not why?

Original source