C++ Constructor Create different constructors for the single class

Description

C++ Constructor Create different constructors for the single class

#include <iostream>

using namespace std;

class MyClass//from www .j a v a2  s .c  o m
{
protected:
    string ChildName;
    int Toys;

public:
    MyClass(int count, string name)
    {
        ChildName = name;
        Toys = count;
    }

    MyClass(string name)
    {
        ChildName = name;
        Toys = 0;
    }
};

int main()
{
    MyClass inst1("A");
    MyClass inst2(123, "B");
}



PreviousNext

Related