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 175 views
4 answers 301 views
2 answers 217 views
1 answer 179 views
1 answer 137 views
137 views asked Dec 1, 2022 by avibootz
1 answer 187 views
...