Jump to content
  • Advertisement
Sign in to follow this  
AcidZombie24

using a class instead of a type

This topic is 3553 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 was thinking, is there a way for me to have a class that works exactly like a type with no performance lost? here is an example
template<class T>
struct NativeTypeWrap
{
 typedef somePersonalType someType;
 T val;
 operator const T&() { return val; }
 T& operator =(const T& v) { val = v; return val; }
};
typedef NativeTypeWrap<short> u16;

^ that is untested but its something i like to do. The idea is it works exactly like short does in every way except i am attaching typedefs to it for overloading reasons. I have a class that doesnt want ints but specific size structs which can be ints but would need a typedef. I'd like the code to fail if i pass in an type that doesnt have those typedefs in it (so i know if i goofed up).

Share this post


Link to post
Share on other sites
Advertisement
Classes ARE types. You mean "... instead of a primitive", or perhaps "instead of a typedef".

And in C++, there is no likely performance loss for this kind of thing, certainly not in release mode.

Share this post


Link to post
Share on other sites
Yeah, i want something used like a type_traits but this would hold different data.
What i mainly wanted to know is if something would bite me in the ass while doing this.

also, i need to implement each and every operator overload? or is there a way to only implement a few which would carry out the rest? maybe i can inherit something that already does this?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!