C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

RTTI

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Jupiter
Guest





PostPosted: Mon Aug 23, 2004 10:35 am    Post subject: RTTI Reply with quote



where is RTTI heavily used (in template or in virtual class) ??
[consider coding level not compiler level]

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Stefan Heinzmann
Guest





PostPosted: Mon Aug 23, 2004 10:16 pm    Post subject: Re: RTTI Reply with quote



Jupiter wrote:

Quote:
where is RTTI heavily used (in template or in virtual class) ??
[consider coding level not compiler level]

What is a virtual class? Do you mean classes with virtual functions?
Well, RTTI is only available in classes with at least one virtual
function, so your question sort of answers itself.

--
Cheers
Stefan

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
llewelly
Guest





PostPosted: Mon Aug 23, 2004 10:30 pm    Post subject: Re: RTTI Reply with quote



[email]pravin.shelar (AT) rediffmail (DOT) com[/email] (Jupiter) writes:

Quote:
where is RTTI heavily used (in template or in virtual class) ??
[consider coding level not compiler level]


In classes that have virtual functions. All class which have virtual
functions support RTTI. Classes which do not have virtual
functions do not support RTTI.

RTTI and templates are independent; if a class template has no
virtual functions, it does not support RTTI. If class template
*does* have virtual functions, it does support RTTI.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Roger Orr
Guest





PostPosted: Tue Aug 24, 2004 10:49 pm    Post subject: Re: RTTI Reply with quote

"Jupiter" <pravin.shelar (AT) rediffmail (DOT) com> wrote

Quote:
where is RTTI heavily used (in template or in virtual class) ??
[consider coding level not compiler level]

As other have said, in classes w/ virtual functions.
What difference does the answer make - ie what made you ask the question in
the first place?

Roger Orr
--
MVP in C++ at www.brainbench.com



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
jive
Guest





PostPosted: Fri Aug 27, 2004 2:49 am    Post subject: Re: RTTI Reply with quote

"llewelly" <llewelly.at (AT) xmission (DOT) dot.com> wrote

Quote:
pravin.shelar (AT) rediffmail (DOT) com (Jupiter) writes:

In classes that have virtual functions. All class which have virtual
functions support RTTI. Classes which do not have virtual
functions do not support RTTI.

How do you planned to implement down cast on class hierarchy were there
is no virtual functions and only trivial destructor?

AFAIK RTTI and dynamic binding are separate qualities not bound to each
other.

Furthermore, if RTTI is not used compiler may optimize it away, even if
there is virtual functions and base classes.

- jive



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
llewelly
Guest





PostPosted: Sat Aug 28, 2004 2:45 am    Post subject: Re: RTTI Reply with quote

"jive" <jive (AT) nospam (DOT) invalid> writes:

Quote:
"llewelly" <llewelly.at (AT) xmission (DOT) dot.com> wrote in message
news:86llg5kikk.fsf (AT) Zorthluthik (DOT) local.bar...
[email]pravin.shelar (AT) rediffmail (DOT) com[/email] (Jupiter) writes:

In classes that have virtual functions. All class which have virtual
functions support RTTI. Classes which do not have virtual
functions do not support RTTI.

How do you planned to implement down cast on class hierarchy were there
is no virtual functions and only trivial destructor?

$ cat dynamic_cast.cc

struct no_rtti_base{};
struct no_rtti_derived:no_rtti_base{};

struct rtti_base
{
virtual ~rtti_base(){}
};

struct rtti_derived:rtti_base{};

struct rtti_no_rtti_base:no_rtti_base
{
virtual ~rtti_no_rtti_base(){}
};

int main()
{
rtti_derived rd;
rtti_base* rbp= &rd;
//dynamic_cast<> permitted, because rtti_* has virtual
//function(s).
rtti_derived* rd2= dynamic_cast<rtti_derived*>(rbp);

no_rtti_derived nrd;
no_rtti_base* nrbp= &nrd;
//dynamic_cast<> is a compile time error, because no_rtti_base
//does not have virtual function(s)
no_rtti_derived* nrdp= dynamic_cast<no_rtti_derived*>(nrbp);

rtti_no_rtti_base rnrb;
no_rtti_base* nrbp2= &rnrb;
//dynamic_cast<> is a compile time error, because no_rtti_base
//does not have virtual function(s)
rtti_no_rtti_base* rnrbp= dynamic_cast<rtti_no_rtti_base*>(nrbp2);
}
$ g++ dynamic_cast.cc
dynamic_cast.cc: In function `int main()':
dynamic_cast.cc:29: error: cannot dynamic_cast `nrbp' (of type `struct
no_rtti_base*') to type `struct no_rtti_derived*' (source type is not
polymorphic)
dynamic_cast.cc:35: error: cannot dynamic_cast `nrbp2' (of type `struct
no_rtti_base*') to type `struct rtti_no_rtti_base*' (source type is not
polymorphic)

Without virtual functions, dynamic_cast<> is not allowed. Note that
this is not about how I plan to implement anything; it is what
the standard requires, and what many implementations have done
for years.

Quote:
AFAIK RTTI and dynamic binding are separate qualities not bound to each
other.

This is not so in ISO C++. There are several compiliers which allow
one to use a compile-time flag which disables rtti for
*everything*, and still use virtual functions, but they are
non-conforming in that mode, because they do not provide
dynamic_cast at all.

Quote:

Furthermore, if RTTI is not used compiler may optimize it away, even if
there is virtual functions and base classes.

This is true, but to prove the RTTI for a type T is not used, the
compiler must analyze every module which uses any object of type
T, T*, T&, and cv-qualified variants thereof. That's not always
feasible; most implementations support shared libraries, which
either prevents said analysis entirely, or require it to be done
at the time the libraries are loaded. (Does anyone know of an
implementation which does optimizations at library-load time? It's
possible, I'm sure, but I don't know of any examples.)



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.