Determining if a Class is .... ?

  • Thread starter Kristofer Pettijohn
  • Start date
K

Kristofer Pettijohn

Greetings,

I'm trying to figure out if there is a way to determine whether a class
has the traits of another class...

For example...

I have a class called Square, which inherits Cube, which inherits Shape ..

I am writing another class that will get passed a class as a template
parameter...

MyNewClass<Square> object;

Inside of MyNewClass, is there a way to determine if the class passed to
it through the template is an object with the traits of Shape? I'd HOPE
to catch it at Compile-time, but run-time (using assert() perhaps?) would
be fine, too.

I hope I am asking this right..'tis a bit late.

Thanks for any help or pointers!

Kristofer
 
J

John Harrison

Kristofer Pettijohn said:
Greetings,

I'm trying to figure out if there is a way to determine whether a class
has the traits of another class...

For example...

I have a class called Square, which inherits Cube, which inherits Shape ..

I am writing another class that will get passed a class as a template
parameter...

MyNewClass<Square> object;

Inside of MyNewClass, is there a way to determine if the class passed to
it through the template is an object with the traits of Shape? I'd HOPE
to catch it at Compile-time, but run-time (using assert() perhaps?) would
be fine, too.

I hope I am asking this right..'tis a bit late.

Thanks for any help or pointers!

Kristofer

Boost type_traits library can do this
http://www.boost.org/libs/type_traits/index.htm

You also might want to check out 'Modern C++ Design' by Andrei Alexandrescu
where this and a lot more else besides is discussed.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top