I think this is a silly question to ask but ... is there any way to use the constructers (overloaded or default) as the setters for a class?
here is some code:
Code:#include <iostream>
using namespace std;
class thing
{
protected:
int number;
public:
thing();
thing(int newNum);
void SetNum ( int newNum );
};
thing::thing()
{
number = 42;
}
thing::thing(int newNum)
{
number = newNum;
}
void thing::SetNum( int newNum )
{
// want to use thing(); or thing(int newNum) here
}
int main()
{
thing things(2);
things.SetNum(1);
return 0;
}
obviously this is a silly example, but I have a bigger class which has about 5 or 6 constructers, and it needs the same amount of setters ... I could just copy and paste, in fact i have done so, but I was hoping there is a way to use the constructers in setters.
Does anyone know how to do this? Is it possible?