Sign in to follow this  

Class Comparisons - Third Party to Second Party to First

This topic is 4733 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have yet another question... Is there some way to compare classes of certain objects? Can it be done using 'template'? My Psuedo Code: (an example)
template <class objType>
bool isInt(objType &var) {
 if (objType==int) return true; //Remember, Psuedo
 else return false;
}
I found something about the function 'same_type_p', but it doesn't work on Dev-C++ (4.9.9.1). I don't know where the header is for it. (RESOLVED) One more question... (RESOLVED) New question! I now have the typeid operator, and a method to pass classes to functions, but now I need to figure out if a certain class (of a pointer) is either the same or a descendant of another class (using polymorphism and inheritance). [Edited by - deadimp on December 31, 2004 5:34:49 PM]

Share this post


Link to post
Share on other sites
This can easily be achieved using template specialization.

template <typename T>
bool is_int(T & x)
{
return false;
}

template <>
bool is_int(int & x)
{
return true;
}

Share this post


Link to post
Share on other sites
Thanks! That helped alot.
One more question: How do you pass classes to functions, without using templates?
Psuedo Code:
void func(class X) {
//Use class X and typeid
}

Share this post


Link to post
Share on other sites
It wasn't too imperative. Though I found you could do this:
template <class T>
bool func() {
//Code
}
//Calling func()
func<int>();

Looks kinda messy, but it works. Thanks for your help.

Share this post


Link to post
Share on other sites
God that made my head hurt. I think I'm gonna take the easy way and make an array of 'parent' pointers inside of the class (I'm lazy). However, I shall come back to that article once I feel I think I can understand it. Thanks.

Share this post


Link to post
Share on other sites

This topic is 4733 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this