Jimmy,
Yes, you are correct. This kind of feature is supported by C++ and its
generally called as RTTI (Run Time Type Idendification).
There is a small syntax problem with your code. The typeid() returns an
object of type type_info and it has a member function name() to get the
object name string.
Here is the corrected code
myClass::doSomething() {
cout << typeid(this).name();
}
hope this works for you. good luck.
regards,
Thanga
On Mon, Jan 25, 2010 at 8:43 AM, Jimmy Johnson <[email protected]> wrote:
>
>
> There is a feature/object/intety [I'm not sure what the c-terminology is]
> called `typeid' in <typeinfo> that takes an object as argument with a
> feature called name, as in
>
> cout << typeid(anObject).name()
>
> It "Returns a null-terminated character sequence with a human-readable name
> for the type."
>
> My problem seems to be with the self reference usage in
>
> myClass::doSomething() {
> cout << typeid(this).name;
> }
>
> What am I missing?
>
>
> --- In [email protected] <c-prog%40yahoogroups.com>, Tyler
> Littlefield <ty...@...> wrote:
> >
> > hello,
> > c++ doesn't store the name of the class in the binary, you'll have to
> store that yourself if you want it.
> >
> > Thanks,
> > Tyler Littlefield
> > http://tds-solutions.net
> > Twitter: sorressean
> >
> > On Jan 24, 2010, at 7:35 PM, Jimmy Johnson wrote:
> >
> > > Thanks to Tyler, Peter, Furgan for your quick help. Wow!
> > >
> > > I have another. I am trying to simply print a statement containing the
> name of the generating class (or type of the object) when the constructor is
> called. Like...
> > >
> > > myClass::myClass() {
> > > cout << "Debug: call constructor for ";
> > > cout << typeid(this).name << "\n";
> > > };
> > >
> > > The compiler complains with
> > > error C3867: 'type_info::name': function call missing argument list;
> use '&type_info::name' to create a pointer to member
> > >
> > > So I change the above to include & in front of typeid and get:
> > > error C2276: '&' : illegal operation on bound member function
> expression
> > >
> > > So, what's with that?
> > >
> > >
> >
>
>
>
[Non-text portions of this message have been removed]
------------------------------------
To unsubscribe, send a blank message to
<mailto:[email protected]>.Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/c-prog/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/c-prog/join
(Yahoo! ID required)
<*> To change settings via email:
[email protected]
[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/