0

I need little help with dynamic_cast

I have a base class Student and a base class Teacher. I also have a class Demonstrator(students that assist teachers helping other students), that derives from both Student and Teacher. To differentiate demonstrators from regular students i tried: Demonstrator *d=dynamic_cast<Demonstrator *>(students[i]); //students is an array of objects from the class Student But the compiler sends an error message: error: cannot dynamic_cast '*(students + ((sizetype)(((long long unsigned int)i) * 8)))' (of type 'class Student*') to type 'class Demonstrator*'

14th May 2021, 8:29 AM
Mihail
Mihail - avatar
2 Respostas
+ 1
Is your "students" class polymorphic ? ( Means does it have any virtual function ? )
14th May 2021, 8:42 AM
Arsenic
Arsenic - avatar
+ 1
Thanks. I forgot that.
14th May 2021, 12:01 PM
Mihail
Mihail - avatar