Jump to content

Recommended Posts

Posted

//if a constructor only has one parameter, there is a third way to pass an initial value to that constructor

#include <iostream>

using namespace std;


class X{

	int a;

public:

	X(int j) { a=j;}

	int get_a() {return a;}

};

int main()

{

	X ob=99; //passes 99 to j

	cout<<ob.get_a(); //outputs 99


	system("PAUSE");

	return 0;

}

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.