hello,

i'm new to cpp &

I wanna know that in C++

if there is multiple inheritance is done

suppose,

Class A & Class B public,protected member

is inherted in Class C

like,

class A
{
	protected:
		int no1;

	public:
		void get_a(void)
		{
		cout<<"Class A";
		}

};
class B
{
	protected:
		int no2;
	public:
		void get_b(void)
		{

		cout<<"Class  B";
		}

};
class c : public A,b
{
	private:
		int no;


};

so, how compiler will distinguish that get_a(),no1 is come from class A & get_b(),no2 is come from class B

i have surf lot of web site but i can't get any idea pls help to solve this question.

thanx in advance

C++ is case sensitive, so class c : public A,b should be class C : public A, B

I won't have to.
When you create an object of class C, both get_a, get_b will be available for calling.
If however, both function was named get(), then it would cause ambiguity.

class A
{
	protected:
		int no;

	public:
		void get(void)
		{
		cout<<"Class";
		}

};
class B
{
	protected:
		int no1;
	public:
		void get_a(void)
		{

		cout<<"Class";
		}

};
class C : public A,B
{
	private:
		int no;


};

//inside main
C c;
c.get() //error. which get()?
c.A::get() //oh, so you mean A' get. No problem
commented: Signing off for today, so here's a wave goodbye. See you in a year! +18

so, how compiler will distinguish that get_a(),no1 is come from class A & get_b(),no2 is come from class B

Does it matter? If you look at the relationship you created, Class C is a Class A and a Class B. Therefore Class C has the methods get_a and get_b, which parent they come from is irrelevant.

so, how compiler will distinguish that get_a(),no1 is come from class A & get_b(),no2 is come from class B

i have surf lot of web site but i can't get any idea pls help to solve this question.

thanx in advance

I think below program will help u to understand,

class Father{
private:
    int money;
public:
    void Nokia_Mobile(void){
        cout << "I m Father's Nokia Mobile " << endl;
    }
};

class Mother{
private:
    int money;
public:
    void Samsung_Mobile(void){
        cout << "I m Mother's Samsung Mobile " << endl;
    }
};

class Son:public Father,public Mother{
private:

public:


};

int main(){
    Son john;
    john.Nokia_Mobile();
    john.Samsung_Mobile();
    return 0;
}

here u can access ur father and mother's mobile if they are public(mean if they are not password protected) so u can call and play games on both mobiles.. but cant access ur parents money(in most cases) as money is private for u.

Does it matter? If you look at the relationship you created, Class C is a Class A and a Class B. Therefore Class C has the methods get_a and get_b, which parent they come from is irrelevant.

exactly. It is irrelevant from which parent the method has come. But even if the compiler needed to know that:
Out of the 2 classes from which class C is inherited, get_a() method is defined only in class A and get_b() method is only defined in class B in your code. Hence we can easily see from which parent the method has come

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.