Search This Blog

Loading...

how to create a constuctor with multiple arguments/parameters in c++

#include<stdio.h>
#include<conio.h>

class demoClass
{
    private:
        string name;
        int add;


    demoClass(string x)    //constructor with single parameter/argument.
    {
        setName(name);
    }

    demoClass(int x,int y)        //constructor with two parameter/argument.
    {
        int add = x + y;
    }


    public:
        void setName(string x)
        {
            name=x;
        }

        void getName(string x)
        {
            return name;
        }

};


void main()
{
    demoClass obj("single parameter constructor.");        //calling single parametr constructor.

    demoClass obj(2,3);    // calling a constructor with two parameters.
}

No comments:

Post a Comment