Determining if a Class is .... ?

Discussion in 'C++' started by Kristofer Pettijohn, Aug 31, 2003.

  1. 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
     
    Kristofer Pettijohn, Aug 31, 2003
    #1
    1. Advertising

  2. "Kristofer Pettijohn" <> wrote in message
    news:3f51a9f2$0$77770$...
    > 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
     
    John Harrison, Aug 31, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. WJ
    Replies:
    10
    Views:
    799
    Chris Smith
    May 19, 2004
  2. E11
    Replies:
    1
    Views:
    4,901
    Thomas Weidenfeller
    Oct 12, 2005
  3. Stephen Nesbitt
    Replies:
    0
    Views:
    283
    Stephen Nesbitt
    Nov 22, 2004
  4. Mark English
    Replies:
    9
    Views:
    389
    Mike C. Fletcher
    Jan 22, 2005
  5. Art Gillespie
    Replies:
    5
    Views:
    143
    Robert Klemme
    Oct 8, 2005
Loading...

Share This Page