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; }

24th Nov 2016, 8:59 AM
Adhiraj Majumdar
Adhiraj Majumdar - avatar
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.
24th Nov 2016, 9:04 AM
Magyar DĂĄvid
Magyar DĂĄvid - avatar
+ 1
^up it's C++, not Java. You've forgot about semicolon after d.sayHi()... it should be "d.sayHi();"
24th Nov 2016, 10:18 AM
Jakub Stasiak
Jakub Stasiak - avatar