Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to use multiple inheritance to inherit two base classes in C++

1 Answer

0 votes
#include <iostream>

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

class Base1 {
	int a;
public:
	Base1(int _a) {
		a = _a;
	}
	int get_a() {
		return a;
	}
};


class Base2 {
	int b;
public:
	Base2(int _b) {
		b = _b;
	}
	int get_b() {
		return b;
	}
};


class Derived : public Base1, public Base2 {
	int c;
public:
	Derived(int _a, int _b, int _c) : Base1(_a), Base2(_b) {
		c = _c;
	}

	void print() {
		cout << get_a() << ' ' << get_b() << ' ' << c << endl;
	}
};

int main()
{
	Derived o(3, 6, 9);

	o.print();

	return 0;
}



/*
run:

3 6 9

*/

 



answered Mar 5, 2018 by avibootz
edited Mar 5, 2018 by avibootz

Related questions

1 answer 209 views
1 answer 224 views
1 answer 172 views
1 answer 220 views
...