I am editing some c++ and all of the built in types have been wrapped in a corresponding wrapper class. All of the operators have been overloaded to do bizarre things like operator[] coded to ignore the argument or to exactly what the underlying type would do. Is this malevolent or is there some possibility this is a good idea in some other universe.

  • 1
    I really dont understand the point of your question. I think you should make a better description about it...
    – JulioC
    Commented Oct 16, 2010 at 6:23
  • 3
    Sounds like madness to me. Commented Oct 16, 2010 at 6:41
  • 1
    Do you literally mean 'class CDouble { double _data; ctor(), operator=(), operator==(), operator<(), operator !=()}' ? Commented Oct 16, 2010 at 17:36
  • Yes. In every class &= was redefined to swap the values of the two operands
    – rerun
    Commented Nov 18, 2010 at 15:38

2 Answers 2


IMO, your question is made of 2 questions:

Is a good idea to wrap built-in/3rd party types in own types?

Depends. Having own types around existing types is great when you change the underlying type because the existing logic can be preserved (ideally) with no changes. Is like having a 3 tire architecture and you can change the database without changing the business logic. However, creating all those types takes time and developers also need time to learn them...

Is a good idea to code own types that behave different from the original types when using the same syntax?

No. Is bad because it has side effects. Strange bugs may appear because one wasn't aware of the new behavior. Also makes debugging complicated and increases the time/cost of the development process.


Though I have never seen C++ code used this way. In C, stack implementations typically do not use built in types directly. They usually have some MY_INT_32 (not event int32_t from stdint.h). This is required for very high portability. You will be amazed by the peculiarities of some of the platforms (12 bit integers anyone?).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.