0

What is wrong in below code?

https://code.sololearn.com/ca223a172A22 //Compilation error 'class Person' has no member named 'getdata'

7th May 2021, 4:14 PM
𝖆𝖙.𝖚𝕷
𝖆𝖙.𝖚𝕷 - avatar
1 Resposta
+ 3
You have an array of Person pointers, so when it calls getdata() it will read that pointer as a Person object regardless of what it was instanced as, so when it tries to read getdata it sees that the object (which it's reading as a Person) doesn't have a getdata() method. You'd have to cast it. Or you could put a virtual method which will let it know that a child class could override the method (I THINK; not sure) like this: public: virtual void getdata() = 0; virtual void putdata() = 0; In the person class What are the inputs supposed to be? I can't really find out what will fix it if I don't know what to input.
7th May 2021, 4:28 PM
Odyel
Odyel - avatar