2

Here is a simplified version of my scenario:

class Base
{
    class Entry
    {
        ...
    }

    std::vector<Entry *> entryList;

    void processEntry() = 0;

    void OnProcessEntry(); // processEntry callback
};

class Derived : public Base
{
    class Entry : public Base::Entry
    {
        ...
    }

    void processEntry() 
    {
         ...
         entryList.push_back(new Entry); 
         OnProcessEntry();
    }
};

When I copy a Derived::Entry pointer into entryList, the object is sliced to Base::Entry. Is there any way I can get the Entry back to its original "unsliced" state within the base class method OnProcessEntry?

If anybody can recommend a more appropriate title please do and I will edit.

Thanks.

not an alien
  • 651
  • 4
  • 13
  • 3
    "When I copy a Derived::Entry pointer into entryList, the object is sliced to Base::Entry" why do you think so? You should reread what object slicing is. It appears with objects. Pointers dont slice. – 463035818_is_not_an_ai Jun 21 '19 at 10:05
  • If you have some code with an actual problem, then you should show that. There is no problem in the example you posted here. – 463035818_is_not_an_ai Jun 21 '19 at 10:07
  • @formerlyknownas_463035818 Because when I look at the pointers inside `entryList` when debugging, I can no longer see the members exclusive to Derived::Entry, only the base members. If that isn't slicing, then what is it? – not an alien Jun 21 '19 at 10:10
  • 2
    thats not slicing, thats the interface you can access via a `Base` pointer. The data is still there (not sure how to see it with a debugger though). Cast the pointer to `Derived*` and you can access also `Derived`s members – 463035818_is_not_an_ai Jun 21 '19 at 10:12
  • Get a better debugger? – melpomene Jun 21 '19 at 10:12
  • 1
    please try to include such information in the question. It appears that your actual question/problem is that your debugger shows you only `Base` interface for a `Base` pointer, but thats actually not a big surprise... – 463035818_is_not_an_ai Jun 21 '19 at 10:14
  • @formerlyknownas_463035818 I see, that's very interesting. I didn't know that and hopefully you can see why I made the incorrect assumption. Thank you for teaching me something. :) – not an alien Jun 21 '19 at 10:14
  • i will flag this as a duplicate, it is not really the same question, but it explains why your premise is broken, if you want a dedicated answer, please fix your questin to include why you think your code has a problem / what is the actual "problem" you want to fix – 463035818_is_not_an_ai Jun 21 '19 at 10:21
  • Ok. I was thinking maybe I should delete the question. Do you think it is better that I edit to include what lead me to think what I did and keep it up? – not an alien Jun 21 '19 at 10:24
  • @notanalien You probably should explain the whole story regarding your debug observations in your question title and body. – πάντα ῥεῖ Jun 21 '19 at 11:19

0 Answers0