473,782 Members | 2,454 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Determining if a Class is .... ?

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

Jul 19 '05 #1
1 1523

"Kristofer Pettijohn" <kr*******@cybe rnetik.net> wrote in message
news:3f******** *************** @newsreader.cyb ernetik.net...
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<Squa re> 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
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1241
by: Stephen Nesbitt | last post by:
All: Here's my implementation problem. I have a base class which has the responsibility for providing entry into the logging system. Part of the class responsibility is to ensure that lagger names are consistent. For all intents and purposes this class should be considered abstract and will always be subclassed. What I want to do is the following: - allow the logger name to set explicitly. I've accomplished this by
8
2534
by: Mark English | last post by:
I'd like to write a Tkinter app which, given a class, pops up a window(s) with fields for each "attribute" of that class. The user could enter values for the attributes and on closing the window would be returned an instance of the class. The actual application I'm interested in writing would either have simple type attributes (int, string, etc.), or attributes using types already defined in a c-extension, although I'd prefer not to...
1
26963
by: Simon Wigzell | last post by:
I am adapting a javascript pulldown menu system to my dynamic website generator - the arrays that hold the menu items information are read from a database and will be different for different users of my system. Unfortunately the javascript menu system requires that each menu cell's width be dimensioned. if I don't hard code a large enough value then long menu item names are trimmed, besides the fact that it then looks ugly for most menu...
2
2253
by: Phil Galey | last post by:
In VB.NET I find the IO object very handy in replacing most of the functionality of the FileSystemObject. One exception, however, is in determining the size of a file. How can you determine the size of a file in VB.NET without adding the FileSystemObject to your project?
3
1926
by: Steve Brown | last post by:
Hello all, Is there a way to determine a variable's type at run-time? The reason I'm asking is that i have code that looks like this: template <class T> Object::Object(int TypeCode, T* data) { switch (TypeCode) case 1:
2
3646
by: Garrett | last post by:
Need any help in determining which groups have been given security access to a folder. Searched DirectoryServices to no avail... Any Help?
9
1634
by: Clay_Culver | last post by:
I need to find out if an object is a class. Using new style classes this is very easy: class Test(object): pass obj = Test or obj = Test() if type(obj) == type:
2
8209
by: patrimith | last post by:
Hi List, I am used to the following with Java: import some.package.MyClass; name = MyClass.class.getName(); The value for name will be "some.package.MyClass". For Python, I find:
3
3111
by: Gordon | last post by:
I am currently working on some code for my CMS that creates a site folder, then creates all the necessary child folders inside it. The method that creates folders needs to insert into 2 tables so it wraps the operation in a transaction. (psuedocode below) public function createItem ($parent) { $this -database -beginTransaction (); $this -database -query ('INSERT INTO items (param1, param2 ... ) values (val1, val2 ... )');
8
2616
by: Fuzzyman | last post by:
Hello all, I may well be being dumb (it has happened before), but I'm struggling to fix some code breakage with Python 2.6. I have some code that looks for the '__lt__' method on a class: if hasattr(clr, '__lt__'): However - in Python 2.6 object has grown a default implementation of
0
9479
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10311
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10146
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9942
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6733
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5509
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4043
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3639
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2874
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.