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 

pointer to type_info

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
John Torjo
Guest





PostPosted: Tue Jul 20, 2004 6:03 am    Post subject: pointer to type_info Reply with quote



Hi,

Heres's what the standard says:
[expr.typeid] 5.2.8 Type identification
The result of a typeid expression is an lvalue of static type const
std::type_info (18.5.1) and dynamic type const std::type_info or const
name where name is an implementation defined class derived from
std::type_info which preserves the behavior described in 18.5.1. The
lifetimeof the object referred to by the lvalue extends to the end of
the program. Whether or not the destructor is called for the type_info
object at the end of the program is unspecified.

Quick question:
If I read this correctly, I can hold a pointer to dereferencing a
typeid(), and that pointer will last throughout the program. Am I
correct?
Example:
some_class * p = ...;

// this will last throughout the program
const std::type_info * info = &typeid(*p);


Thanks.

Best,
John


John Torjo
Freelancer
-- [email]john (AT) torjo (DOT) com[/email]

Contributing editor, C/C++ Users Journal
-- "Win32 GUI Generics" -- generics & GUI do mix, after all
-- http://www.torjo.com/win32gui/

Professional Logging Solution for FREE
-- http://www.torjo.com/code/logging.zip (logging - C++)
-- http://www.torjo.com/logview/ (viewing/filtering - Win32)
-- http://www.torjo.com/logbreak/ (debugging - Win32)
(source code available)

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]

Back to top
James Kuyper
Guest





PostPosted: Sat Jul 24, 2004 5:23 am    Post subject: Re: pointer to type_info Reply with quote



[email]jtorjo (AT) yahoo (DOT) com[/email] (John Torjo) wrote in message news:<c638aac5.0407191103.708c6bfd (AT) posting (DOT) google.com>...
...
Quote:
If I read this correctly, I can hold a pointer to dereferencing a
typeid(), and that pointer will last throughout the program. Am I
correct?

Example:
some_class * p = ...;

// this will last throughout the program
const std::type_info * info = &typeid(*p);


I think that what you meant to say is correct, but that you haven't
worded it correctly. You're taking the address of typeid, not
dereferencing it. How long the pointer would last depends upon how
it's defined; assuming that it has static storage duration that's
essentially the same as the length of the program. However, I suspect
that you're not really interested in how long the pointer lasts;
you're interested in how long it remains useable. It is indeed useable
from the moment you assign it that value, until the end of the
program.

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
John Torjo
Guest





PostPosted: Mon Jul 26, 2004 5:03 pm    Post subject: Re: pointer to type_info Reply with quote



[email]kuyper (AT) wizard (DOT) net[/email] (James Kuyper) wrote in message news:<8b42afac.0407231931.219f8a0d (AT) posting (DOT) google.com>...
Quote:
jtorjo (AT) yahoo (DOT) com (John Torjo) wrote in message news:<c638aac5.0407191103.708c6bfd (AT) posting (DOT) google.com>...
..
If I read this correctly, I can hold a pointer to dereferencing a
typeid(), and that pointer will last throughout the program. Am I
correct?

Example:
some_class * p = ...;

// this will last throughout the program
const std::type_info * info = &typeid(*p);


I think that what you meant to say is correct, but that you haven't
worded it correctly. You're taking the address of typeid, not
dereferencing it. How long the pointer would last depends upon how
it's defined; assuming that it has static storage duration that's
essentially the same as the length of the program. However, I suspect
that you're not really interested in how long the pointer lasts;
you're interested in how long it remains useable. It is indeed useable
from the moment you assign it that value, until the end of the
program.

I assume I think that the pointer is useable as long as it lasts ;)

Anyway, internally I need a map that is sorted by std::type_info.
So that I can create a templated function, and see if it's been called
before for the same type.

Best,
John

John Torjo
Freelancer
-- [email]john (AT) torjo (DOT) com[/email]

Contributing editor, C/C++ Users Journal
-- "Win32 GUI Generics" -- generics & GUI do mix, after all
-- http://www.torjo.com/win32gui/

Professional Logging Solution for FREE
-- http://www.torjo.com/code/logging.zip (logging - C++)
-- http://www.torjo.com/logview/ (viewing/filtering - Win32)
-- http://www.torjo.com/logbreak/ (debugging - Win32)
(source code available)

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards 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.