If I want to make a method to return an object's type, what type should the method return? A string, the object itself? Any suggestions?
LindaWiklund
0
Newbie Poster
Recommended Answers
Jump to Post
System::Type^
note: you do not need a method to do this; useSystem::Object::GetType()
instead.
eg.System::Type^ type = obj->GetType() ;
Jump to Postare you on ISO C++ or C++/CLI (the .net variety)?
Jump to Posti'm sorry; i was under the impression that you were on C++/CLI
in standard C++, the type of an expression is given by thetypeid
operator which yields
aconst std::type_info&
eg.#include <typeinfo> template< typename T >inline const std::type_info& get_type( T& object ) { …
Jump to Postcan I use it like this:
const std::type_info& get_type( const MyClass* object )
{
return typeid(object) ;
}And to call it
obj->get_type(myObj);yes, you can. remember though that the type of the variable
object
is a pointer and this would give you the type of the pointer. if …
All 13 Replies
LindaWiklund
0
Newbie Poster
vijayan121
1,152
Posting Virtuoso
LindaWiklund
0
Newbie Poster
LindaWiklund
0
Newbie Poster
vijayan121
1,152
Posting Virtuoso
LindaWiklund
0
Newbie Poster
vijayan121
1,152
Posting Virtuoso
LindaWiklund
0
Newbie Poster
vijayan121
1,152
Posting Virtuoso
LindaWiklund
0
Newbie Poster
LindaWiklund
0
Newbie Poster
vijayan121
1,152
Posting Virtuoso
LindaWiklund
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.