1

I'm supposed to find out what object is p pointing to and write out the functions. And also I'm not supposed to use virtual. I've been stuck on this for a while and would appreciate any help.

class Employee ;
class Secretary : public Employee ;
class Manager : public Employee ;
class Director : public Manager ;
// ...
void f( Employee *p) {
// what class does p belong to?
}
Archy
  • 33
  • 6
  • You can use the result of [`dynamic_cast`](http://en.cppreference.com/w/cpp/language/dynamic_cast) to figure out what derived class you have, however your class needs to have a vtable (i.e. at least one virtual function) for `dynamic_cast` to work. – vsoftco Dec 13 '15 at 18:50
  • 1
    What do destructors have to do with this? – Emil Laine Dec 13 '15 at 18:50
  • if you are not supposed to use virtual function, this is not acceptable. Otherwise here you go:http://coliru.stacked-crooked.com/a/0a25ce82b62981f0 – Steephen Dec 13 '15 at 18:55
  • You can use `#include` which has a class template `is_same` which will help you know the type. I'm suggesting this because you are nt using `virtual function` – Ankit Acharya Dec 13 '15 at 18:57
  • @Ankit , `is_same` will not help here, as it compares two _already known_ types, and the problem is to _know_ a real type of object. Best way is to add a field to Emloyee which will tell actual type, C-style. – Revolver_Ocelot Dec 13 '15 at 19:13

0 Answers0