Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

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

2 Answers 2

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?).

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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