Hi! My problem is the following. I'd like to call a constructor from within a different constructor to prevent code duplication.
E.g. the first constructor sets the first attribute and another constructor sets a second attribute and then calls the first constructor to set the first one, too.
In Java you can just call
If you do the same in C++ it just defines a new object of the class Test.
Is there a way of doing this in C++?
Thanks in advance for an answer.
KaiDaniel.
E.g. the first constructor sets the first attribute and another constructor sets a second attribute and then calls the first constructor to set the first one, too.
Code:
Test::Test(int a)
{
this->a = a;
}
Test::Test(int a, int b)
{
this->b = b;
Test::Test(a); // this does not work
}
In Java you can just call
Code:
Test(a);
Is there a way of doing this in C++?
Thanks in advance for an answer.
KaiDaniel.