RTTI and CObject Question

B

Bryan

If I have this:
// .h
class Base : public CObject
{
public:
DECLARE_DYNAMIC(Base)
}

class Derived : public Base
{
public:
DECLARE_DYNAMIC(Derived)
}

If I try to do something like this in the .cpp file, Im not getting what
I expected:
// .cpp stuff
IMPLEMENT_DYNAMIC(Base, CObject)
IMPLEMENT_DYNAMIC(Derived, Base)

Derived derived_class;
BOOL b = derived_class.IsKindOf(RUNTIME_CLASS(Derived));
// This returns false!

BOOL b = derived_class.IsKindOf(RUNTIME_CLASS(Base));
// Returns true...

I thought from reading the docs that that BOTH of these would return
true. This is in fact the kind of behavior I am looking for, but so far
no luck.

What am I doing wrong, or how can I get this functionality?

Thanks,
B
 
J

Jack Klein

If I have this:
// .h
class Base : public CObject
{
public:
DECLARE_DYNAMIC(Base)
}

[snip]

Sorry, but Microsoft's MFC, and all other third-party libraries and
extensions, are not part of the C++ language and are off-topic here.

Microsoft has numerous support groups in the hierarchy, a few of which have .mfc in their names. Another good
place for Windows specific questions is

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
 
B

BobR

Bryan said:
If I have this:
// .h
class Base : public CObject { public:
DECLARE_DYNAMIC(Base)
}

class Derived : public Base { public:
DECLARE_DYNAMIC(Derived)
}

If I try to do something like this in the .cpp file, Im not getting what
I expected:
// .cpp stuff
IMPLEMENT_DYNAMIC(Base, CObject)
IMPLEMENT_DYNAMIC(Derived, Base)

Derived derived_class;
BOOL b = derived_class.IsKindOf(RUNTIME_CLASS(Derived));
// This returns false!

BOOL b = derived_class.IsKindOf(RUNTIME_CLASS(Base));
// Returns true...

I thought from reading the docs that that BOTH of these would return
true. This is in fact the kind of behavior I am looking for, but so far
no luck.
What am I doing wrong, or how can I get this functionality?
Thanks, B

Show your macros for 'DECLARE_DYNAMIC', 'BOOL', 'IMPLEMENT_DYNAMIC',
'RUNTIME_CLASS' and class/struct 'CObject'.

Hint: If *you* didn't define them, you may need to try an NG which discusses
them.

Post a compilable program.

FAQ http://www.parashift.com/c++-faq-lite
 

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