[oolua] Get derived class instead of base

  • From: SteelRat <steelrat@xxxxxxx>
  • To: oolua@xxxxxxxxxxxxx
  • Date: Wed, 28 May 2014 15:36:50 +0400

Hi, Liam. I have a lot of classes dervied from one interface. They are holded in some sort of container class. Container class has a method to get stored object as pointer to base class. In my app it sometimes returns fully workable derived class object, but sometimes only base class object i.e. it has no methods of derived class in its metatable. And then i need to clear container to full it by new object instances. Then, after several seconds or several minutes, it repeats - GET returns base class object with no derived class methods. I don't know why. What is normal behavior for such cases in OOLua?


In test app, container returns object of base class only always. Is there possibility to get full object with methods from derived class?

Test:

*class Base: public std::enable_shared_from_this<Base>**
**{**
**    public:**
**
**        typedef std::shared_ptr<Base> Ptr;**
**
**        Base();**
**        virtual ~Base();**
**        void CommonFunction();**
**    protected:**
**
**        std::string        mValue;**
**};**
**
**
**
**
**class Child: public Base**
**{**
**    public:**
**
**        typedef std::shared_ptr<Child> Ptr;**
**        virtual ~Child();**
**
**        void OnlyTask();**
**    protected:**
**
**        Child();**
**};**
**
**
**
**class Container**
**{**
**public:**
**    void Add(Base::Ptr b)**
**    {**
**        mObjects.push_back(b);**
**    }**
**
**    Base::Ptr Get(size_t n) const**
**    {**
**        return mObjects[n];**
**    }**
**
**private:**
**
**    std::vector<Base::Ptr>    mObjects;**
**};*


Other related posts: