0

I meets some problem with downcast in c++ programming language.
Thus, I needs your help.
My program has 5 classes. They are Employee (abstract class),Salary:public Employee,Hourly:public Employee,Commission:public Employee and BasePlusCom:public Commission.
In main() function,I used vector<Employee*>employees[4];
Then I assigned values to employees.
........
And I used structural syntax BasePlusCom* ComPtr=dynamic_cast<BasePlusCom*>(employees);
.....
And when compiles this program, compiler produces a warning that:
"dynamic_cast" used on polymorphic type 'class Employee' with G/R; unpredictable behavior may result.
And when I change dynamic_cast to reinterpret_cast then program run, but it not work properly.
How does casting in C++ differ?

4
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by vijayan121
0

Post the code please. I can see a few ways around this but it might be better to have a sense of the intent of the program before making a suggestion.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.