What if i have a code like this where class Bsse has no function and derived twice in Diamond way
Output: in Base In Der1 in Base Der 2 Most Derived
Point is until we access any thing common in base class Explicitly there is NO issue
Lets see Accessing any variable from base :
Output : Compilation fails
virtual.cpp: In function `int main()':
virtual.cpp:31: error: request for member `Base_a' is ambiguous
virtual.cpp:6: error: candidates are: int Base::Base_a
virtual.cpp:6: error: int Base::Base_a
To solve we need Virtual inheritance .
Output : See the Constructor Sequence in Base
In Der1
Der 2
Most Derived
Accessing Base_a 0
i tried to print sizes of object also
ReplyDeleteWith one int in Base class :
Nonvirtual :Base(4) der1(4) mostDer(8)
Virtual :Base(8) der1(8) mostDer(12)
Base with no variable:
Nonvirtual :Base(1) der1(1) mostDer(2)
Virtual :Base(1) der1(4) mostDer(8)
Awesome Post
ReplyDeletec++ interview questions
salesforce interview questions
bootstrap interview questions
spring interview questions and answers for experienced
Very nice blog, Thank you for providing good information.
ReplyDeletepython training in bangalore | python online Training
artificial intelligence training in bangalore | artificial intelligence online training
machine learning training in bangalore | machine learning online training
uipath-training-in-bangalore | uipath online training
blockchain training in bangalore | blockchain online training
aws training in Bangalore | aws online training
data science training in bangalore | data science online training
hadoop training in bangalore | hadoop online training
iot training in bangalore | iot online training