
There are 3 classes (one base, two derivatives), and a coherent list (template), the data from these three classes I put in the list, and I deduce. The problem is that when displaying data on the screen, only output for the base class is triggered and its derivatives are not displayed. Maybe something with the list is wrong?
Closed due to the fact that off-topic participants insolor , Abyx , Harry , cheops , iFr0z Nov 29 Nov '17 at 7:31 .
It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:
- “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - insolor, Abyx, Harry, cheops, iFr0z
- C ++ language is used - Tafe SD
|
1 answer
Use virtual functions.
For example,
struct Base { virtual void print(ostream& o); }; inline ostream& operator<<(ostream& o, Base& b) { b.print(o); return o; } - To work with the list I use the operator overloading << output. It can't be virtual to make it - Tafe SD
- add the virtual function that the output statement will invoke. - Abyx
- The program crashes with errors LNK2019: unresolved external symbol, LNK2001: unresolved external symbol. I tried to do it already, I could not find the answers to the mistakes - Tafe SD
- @TafeSD, to you here - Abyx
- Okay, now I will try to fix it - Tafe SD
|