473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

c++ getClass()?

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
4 9470

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

Daniel T. ¼g¹D¡G
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Fred | last post by:
Are primitives objects? int i = 3; System.out.println(i.getClass()); doesn't compile. Get an error message "int can't be dereferenced" But yet the docs for class Object say: Class Object...
1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
3
by: enki | last post by:
I have been doing some reading on dynamic bindind and polymorphism. I know the basics from what I have seen in books. The way virtual methods were explained was that they were used when methods...
2
by: Philipp | last post by:
Hello This seems a simple question, please send me to the right FAQ if I missed it: If there is a class Fruits with two classes Apples and Bananas extending Fruits. Apples has a method called...
5
by: shana07 | last post by:
What is the correct sytanx for getClass()? I don't know how to use it as I read java doc it is something like Class<? extends Object> ..what does it mean? I need to know what class is that and...
10
by: mistb2002 | last post by:
I am trying to modify my program to add and delete inventory items. I tried just adding but I am getting mutliple errors help. This is what my program currently looks like // Display The...
8
by: shreedhan | last post by:
Hi, I'm very new to java... and I'm having a problem in getting a URL URL url; url=getClass().getClassLoader().getResource(name); System.out.println(url); This code works well when I supply...
1
by: desturrr | last post by:
I am having diffuculties while trying to make the path of my files relative. I am using an interface to hold my static variables in order not to mix them with my other codes , just implementing the...
1
by: teachrenee | last post by:
I've been trying to compile this program: // Display The CDs. import java.text.*; import java.util.*; import java.awt.*; import java.awt.FlowLayout; import java.awt.event.ActionListener;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.