dynamic_cast and references

D

Dan Noland

- 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top