dynamic_cast and references

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan Noland

    dynamic_cast and references

    - Hello All -

    I believe that I have a firm understading of dynamic_cast and its
    proper usage, however g++-2.95.4 is telling me that something I believe to
    be possible is not possible.

    I have:

    class ObjectRefList: /*extends*/ public Object {
    /* ObjectRefList Stuff Lives Here */
    public:
    class ObjectRefListIt erator: /*extends*/ public Object {
    ObjectRefListIt erator& operator++();
    bool operator==(Obje ctRefList& aOp) const;
    bool operator!=(Obje ctRefList& aOp) const;
    Object& getCurrent() const;
    }
    }

    Each of my Interfaces has an ObjectRefList called mListeners. So I tried
    something like:

    bool FooInterface::o nClick()
    {
    ObjectRefList:: ObjectRefListIt erator i = mListeners.begi n();
    for(;i != mListeners.end( ); i++)
    {
    dynamic_cast<Fo oInterface&>(i. getCurrent()).o nClick();
    }
    }

    However g++ tells me:

    FooInterface.cp p:41: cannot dynamic_cast
    `+i.ZObjectRefL ist::ZObjectRef ListIterator::g etCurrent()' (of type `class
    Object &') to type `class FooInterface &'

    I was under the impression that dynamic_cast
    (1) worked on references and
    (2) allowed downcasts (when appropriate)

    Please disabuse me of these notions if either of them are untrue.
    Otherwise is this just a g++ issue or am I doing something retarded?

    YT,
    Dan Noland
    Purdue RCS Programmer/Analyst
Working...