Call overriden methods with boost::variant

Help
Val
2014-01-24
2014-01-24
  • Val
    Val
    2014-01-24

    Hi all.

    Firstly, I apologize for my english ;)
    I'm trying to call overriden methods with a boost::variant stored in a vector, without specifying the real type of the stored data.
    Concretely, I'm trying to write something looks like : (sorry, didn't found the C++ code formatting)

    typedef boost::variant\<int, MyClass*> myType;
    std::vector<myType> myVector;
    myVector.push_back(10);

    void push(int i) {
    push_int(i);
    }

    void push(MyClass* ptr) {
    push_myclass(ptr);
    }

    push(myVector[0]);

    without specifying the real type of myVector[0] when calling one of the push() functions.
    Is there any way to do this or should I use virtual class ?

    Thank you all :)

     
    Last edit: Val 2014-01-24