dynamic_cast and references

Discussion in 'C++' started by Dan Noland, Jul 29, 2003.

  1. Dan Noland

    Dan Noland Guest

    - 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 ObjectRefListIterator: /*extends*/ public Object {
    ObjectRefListIterator& operator++();
    bool operator==(ObjectRefList& aOp) const;
    bool operator!=(ObjectRefList& aOp) const;
    Object& getCurrent() const;
    }
    }

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

    bool FooInterface::eek:nClick()
    {
    ObjectRefList::ObjectRefListIterator i = mListeners.begin();
    for(;i != mListeners.end(); i++)
    {
    dynamic_cast<FooInterface&>(i.getCurrent()).onClick();
    }
    }

    However g++ tells me:

    FooInterface.cpp:41: cannot dynamic_cast
    `+i.ZObjectRefList::ZObjectRefListIterator::getCurrent()' (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
     
    Dan Noland, Jul 29, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roger Leigh
    Replies:
    8
    Views:
    477
    Karl Heinz Buchegger
    Nov 17, 2003
  2. Yuming Ma
    Replies:
    1
    Views:
    726
    Jeff Schwab
    Dec 17, 2003
  3. Andreas Sch.

    typeid and dynamic_cast, gcc 3.3

    Andreas Sch., Jan 23, 2004, in forum: C++
    Replies:
    18
    Views:
    1,908
    Janusz Szpilewski
    Jan 29, 2004
  4. exits funnel
    Replies:
    2
    Views:
    601
    exits funnel
    Feb 25, 2004
  5. Replies:
    3
    Views:
    487
    Victor Bazarov
    Nov 10, 2004
Loading...

Share This Page