0
Error in program
#include<iostream> using namespace std; class Mother{ public: Mother(){} void sayHi() { cout<<"say Hi!"<<endl; } }; class Daughter:public Mother { public: Daughter(){} }; int main() { Daughter d; d.sayHi() return 0; }
2 Answers
+ 1
Jakub's answer is right.
//Not valid: x-- The variable 'd' is only declared and gets no value. You have to initialize a new Daughter object: Daughter d = new Daughter(); --x
//No need of initialization.
+ 1
^up it's C++, not Java. You've forgot about semicolon after d.sayHi()... it should be "d.sayHi();"