How to use constructor with parameters in C++

1 Answer

0 votes
#include <iostream>

using std::cout;
using std::endl;

class Base {
	int a, b, c;
public:
	Base(int _a, int _b, int _c) {
		a = _a;
		b = _b;
		c = _c;
	}

	void print() {
		cout << a << " " << b << " " << c << endl;;
	}
};
int main()
{
	Base o(2, 87, 999);

	o.print();

	return 0;
}

/*
run:

2 87 999

*/

 



answered Mar 20, 2018 by avibootz

Related questions

2 answers 277 views
4 answers 471 views
2 answers 326 views
1 answer 261 views
1 answer 202 views
202 views asked Dec 1, 2022 by avibootz
1 answer 281 views
...