Topic: pointer to type_info


Author: jtorjo@yahoo.com (John Torjo)
Date: Mon, 26 Jul 2004 17:03:55 GMT
Raw View
kuyper@wizard.net (James Kuyper) wrote in message news:<8b42afac.0407231931.219f8a0d@posting.google.com>...
> jtorjo@yahoo.com (John Torjo) wrote in message news:<c638aac5.0407191103.708c6bfd@posting.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
-- john@torjo.com

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                       ]





Author: kuyper@wizard.net (James Kuyper)
Date: Sat, 24 Jul 2004 05:23:50 GMT
Raw View
jtorjo@yahoo.com (John Torjo) wrote in message news:<c638aac5.0407191103.708c6bfd@posting.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.

---
[ 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                       ]





Author: jtorjo@yahoo.com (John Torjo)
Date: Tue, 20 Jul 2004 06:03:09 GMT
Raw View
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
-- john@torjo.com

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                       ]