Welcome To The World Of Hacking


Learn Hacking|Teach Hacking|Learn To Secure|Learn To Code

Wednesday

C++ TUTORIAL 18: CONSTRUCTOR

#include<iostream>
using namespace std;

class constructor
{
        int p,q;
    public:
        constructor(int,int); //constructor declared
        void output(void);
};
void constructor :: output(void)
{
    cout<<"p = "<<p<<endl;
    cout<<"q = "<<q<<endl;
}
constructor :: constructor(int x, int y) // constructor defined
{
    p = x;
    q = y;
}

int main()
{
    constructor con(2,4); //constructor call
    con.output();
    return 0;
}

OUTPUT:

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...