hi all. I'm not sure if its possible but can you call a different constructor inside a constructor of a object? ie can i have different constructors call a single constructor to set up the object

class foo
{
public:
       foo(int)
       foo(double)
       //...
};

foo::foo(int number)
{
       this = foo((double)number);  // ?
}

any help would be appreciated. thanks

yes sure you can. For example you might have a reset method that
resets everything to a default constructor :

class A
{
    int c;
    public : 
   A() { c = 1000; }
    A(int x ) { c = x; }
     void reset() { *this = A(0); }     
};
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.