Can you confirm that this design do not create an overhead ?
Posted: 05 Jan 2006, 19:03
Hi, I want to push OO to it's limit in order to get cleaner code. Here is what I want to do :
This way I can use CSquare like this :
I think that with basic compiler optimisations like inlining this code will bring no overhead in my engine. I already asked some friends about it and they seem to think like me, but are not sure.
Since it's CC related and there is some good programmers monitoring this board I though I would ask here.
What is your opinion about this?
Mathieu Pag
- Code: Select all
class CSquare
{
private:
unsigned int m_uiSquareIndex;
public :
// the next 3 functions allow CSquare to be used as an unsigned int in
// arithmetic operations.
inline CSquare(unsigned int);
inline CSquare operator=(unsigned int);
inline operator unsigned int();
// The next 2 functions are why i'd like to use OOP to make the manipulation
// of squares clearer.
unsigned int GetColumn()
{
return m_uiSquareIndex % 8;
};
unsigned int GetRow()
{
return m_uiSquareIndex / 8;
};
};
This way I can use CSquare like this :
- Code: Select all
CSquare csq(A1)
csq += 8; // One row higher. csq is now equat to A2.
csq.GetRow(); // Will return 1 (0 based index)
csq.GetColumn(); // will return 0
I think that with basic compiler optimisations like inlining this code will bring no overhead in my engine. I already asked some friends about it and they seem to think like me, but are not sure.
Since it's CC related and there is some good programmers monitoring this board I though I would ask here.
What is your opinion about this?
Mathieu Pag