Hi FirstPerson,
I've tweaked your code to meet your needs, I think you are trying to acheive something like this.
class Tetris {
public:
bool DrawLine(unsigned int iColId) {
cout << "Draw Line of Tetris"<<endl;
return true;
}
};
template<typename Type>
class vec2D
{
typedef bool (Tetris::*MFPtr)(unsigned int ID);
MFPtr mydrawFuncPtr;
private:
unsigned int Col_id;
public:
Type x;
Type y;
vec2D(Type x0,Type y0) : x(x0), y(y0) { }
vec2D() : x(0),y(0){ mydrawFuncPtr = 0; }
void reset() { x = 0; y = 0; }
//Enables each object member to have its own unique draw func.
void setDrawFunc(MFPtr drawFunc ) { mydrawFuncPtr = drawFunc;}
//get-set methods
unsigned int Color() { return Col_id;}
void Color(int i) { if(i < 0) Col_id = 0; else Col_id = i; }
// WRONG.
//void drawShape(vec2D<Type>& obj,unsigned int colID)
//CORRECTED:
void drawShape(Tetris& obj,unsigned int colID)
{
(obj.*mydrawFuncPtr)(colID);
}
};
int main ()
{
vec2D<int> vec2DTetris[10]; // use this array.
vec2DTetris[0].setDrawFunc(&Tetris::DrawLine);
Tetris t;
vec2DTetris[0].drawShape(t, 4);
return 0;
}
Hope the Above Code help