I have a question (part of my homework) which im unsure of the code's behavior.
I got a class Father, which owns a function "A", function "A" prints "Hello Father".
I got a second class -> class son:public Father, which does not owns function "A".
I got a third class -> class grandson:public son , which owns function "A" which prints "Hello grandson".
Function "A" is not virtual. Please ignore compiling errors, I didnt want to put here a 80 lines of code.
I have another function :
void justPrint(const son& a) {
a.A;
}
Now, what will be printed in the following call :
grandson jeff;
justPrint(jeff);
I'm a bit confused, son dont have the print function (A), so he suppose to call to Father::A (son is a father..)
but, we send jeff (grandson) to the function which recieves son.. and grandson is a son..
I think that it will print
"Hello Father"
But i'm so confused... Will appericiate any help and explenation..
Second thing, What will happen if i will make the following call :
justPrint(1);
justPrintfunction as described will not compile - or at least it won't call functionA. AndjustPrint(1), assuming there is only the function above also will not compile (as1is not a valid classsonobject).Ain the classfatheris virtual or not.