By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,605 Members | 1,415 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,605 IT Pros & Developers. It's quick & easy.

c++ getClass()?

P: n/a
Hi
How can i do something like Java:

if (str.getClass()==String.class){
}
i found that, this syntax has error in g++:

if (typeof(a) == typeof(b)){
}

thanks
from Peter (cm****@hotmail.com)

Nov 15 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a

cmk...@hotmail.com wrote:
Hi
How can i do something like Java:

if (str.getClass()==String.class){
}
i found that, this syntax has error in g++:

if (typeof(a) == typeof(b)){
}
try typeid.

Nov 15 '06 #2

P: n/a
cm****@hotmail.com wrote:
Hi
How can i do something like Java:

if (str.getClass()==String.class){
}
i found that, this syntax has error in g++:

if (typeof(a) == typeof(b)){
}
Try

if (typeid(a) == typeid(b)){

Don't forget to '#include <typeinfo>'

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 15 '06 #3

P: n/a
cm****@hotmail.com wrote:
Hi
How can i do something like Java:

if (str.getClass()==String.class){
}
i found that, this syntax has error in g++:

if (typeof(a) == typeof(b)){
}
class A { public: virtual ~A() { } };
class B : public A { };

int main()
{
A a, b;
assert( typeid( a ) == typeid( b ) );
B c;
assert( typeid( a ) != typeid( c ) );
}

Frankly though, if you need to do the above, then you probably have a design problem.

--
To send me email, put "sheltie" in the subject.
Nov 15 '06 #4

P: n/a

Daniel T. gDG
cm****@hotmail.com wrote:
Hi
How can i do something like Java:

if (str.getClass()==String.class){
}
i found that, this syntax has error in g++:

if (typeof(a) == typeof(b)){
}

class A { public: virtual ~A() { } };
class B : public A { };

int main()
{
A a, b;
assert( typeid( a ) == typeid( b ) );
B c;
assert( typeid( a ) != typeid( c ) );
}

Frankly though, if you need to do the above, then you probably have a design problem.

--
To send me email, put "sheltie" in the subject.
thank you so much :)

Nov 16 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.