469,302 Members | 2,087 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,302 developers. It's quick & easy.

Dynamic Type Check?

I know I have done this in Java, but is there a way to do it in C++?

Type B and C inherit from type A.

In a function, I want to check an instance of A (which can also be B or
C), to see what it is, and move on... something like:

A something;
if( A.typeof(B) )
{
B somethingB = static_cast<B>(something);
// Do things with the B members
}
else if ( A.typeof(C) )
{
C somethingC = static_cast<C>(something);
// Do things with the C members
}
else
{
// Do things with the A members
}

I know I can accomplish something similar with virtual functions
(polymorphism), but can the above be done in any way?

Just curious.
Brian

Jul 20 '05 #1
4 1300
On Thu, 15 Jan 2004 15:01:57 -0500, Brian Genisio <Br**********@yahoo.com>
wrote:
I know I have done this in Java, but is there a way to do it in C++?


You do realise that this is a JavaScript group, don't you?

Try asking in comp.lang.c++

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2
In article <40********@10.10.0.241>, Br**********@yahoo.com enlightened
us with...
I know I have done this in Java, but is there a way to do it in C++?


AFAIK, yes.

Go ask in a C group. :)
--
--
~kaeli~
If a turtle doesn't have a shell, is he homeless or naked?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #3
On Thu, 15 Jan 2004 20:46:21 GMT, Michael Winter
<M.******@blueyonder.co.invalid> wrote:
On Thu, 15 Jan 2004 15:01:57 -0500, Brian Genisio
<Br**********@yahoo.com> wrote:
I know I have done this in Java, but is there a way to do it in C++?


You do realise that this is a JavaScript group, don't you?

Try asking in comp.lang.c++


I forgot to say the answer is, yes.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #4

"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk...
On Thu, 15 Jan 2004 15:01:57 -0500, Brian Genisio <Br**********@yahoo.com>
wrote:
I know I have done this in Java, but is there a way to do it in C++?


You do realise that this is a JavaScript group, don't you?

Try asking in comp.lang.c++

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)


ARGHHHHH!!!!!!!

I feel like a stooge. I actively follow two news groups...
alt.lang.javascript, and alt.lang.c++. I accadently posted to the wrong
group.

The reason I feel so bad, is because I always get frustrated with incorrect
postings to the different groups, weather it be java questions in the
javascript group, or MFC questions in the C++ group.

How about a C++ question in the javascript group?

Blah,
Brian
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Nathan Bloomfield | last post: by
14 posts views Thread by chai | last post: by
8 posts views Thread by Eyeawanda Pondicherry | last post: by
6 posts views Thread by Philipp Schumann | last post: by
4 posts views Thread by mark.olszowka | last post: by
13 posts views Thread by Krivenok Dmitry | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.