C++ kalıtımı

Katılım
10 Ocak 2023
Mesajlar
11
Puanları
1
Yaş
25
Hello everyone,


First of all, I am new to this, so if my question is inappropriate ( Note linked to Ubuntu ) please don't look at my flaw. My C++ abilities are uncertain, so I was hoping that someone could help me in the flowing situation. I have four classes: Class B expands class A, class beta expands alpha class, alpha is a member of A, and beta is a member of B ( or should be ). So the code I think is as folks:

C++:
class alpha{
/* stuff */
}

class beta: public alpha {
/* stuff */
}

class A{
alpha alpha_obj;
/* stuff */
}

class B: public A {
beta beta_obj;
/* stuff */
}

So the question is: Is there a better way to do this? This form looks stupid because it will have a copy of class B alpha and beta, which is not what I really want. Is it a better approach to use some kind of virtual data? This probably seems like something simple that happens often, I'm not very experienced with c ++, so any advice can be highly appreciated!
 

Yeni mesajlar

Forum istatistikleri

Konular
129,773
Mesajlar
929,955
Kullanıcılar
452,532
Son üye
Antimodes

Yeni konular

Geri
Üst