In C++, can I invoke a constructor from another constructor (constructor chaining)?

Joined
Jun 29, 2022
Messages
28
Reaction score
0
As a C# developer, I'm used to iterating through constructors: I've been reading this article online from scaler topics and I wanted to know, Is it possible to achieve this in C++? Both invoking the Class name and using the 'this' keyword fail.

Code:
class Test {
    public Test() {
        DoSomething();
    }

    public Test(int count) : this() {
        DoSomethingWithCount(count);
    }

    public Test(int count, string name) : this(count) {
        DoSomethingWithName(name);
    }
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,979
Messages
2,570,185
Members
46,727
Latest member
FelicaTole

Latest Threads

Top