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 283 views
4 answers 478 views
2 answers 336 views
1 answer 268 views
1 answer 210 views
210 views asked Dec 1, 2022 by avibootz
1 answer 286 views
...