Pure Functions..
-
Hey ppl, I got stuck with this pure thing.. I got a class which contains pure functions: virtual void OnMouseDown(int Button, int X, int Y) = NULL; virtual void OnMouseMove(int X, int Y) = NULL; virtual void OnMouseUp(int Button, int X, int Y) = NULL; virtual bool OnRender(void) = NULL; And I have a derived class which overrides these methods: bool OnRender(void); void OnMouseDown(int Button, int X, int Y); void OnMouseMove(int X, int Y); void OnMouseUp(int Button, int X, int Y); But the compiler says: Error 5 error C2535: 'void CXWindow::OnMouseDown(int,int,int)' : member function already defined or declared Error 6 error C2535: 'void CXWindow::OnMouseMove(int,int)' : member function already defined or declared Error 7 error C2535: 'void CXWindow::OnMouseUp(int,int,int)' : member function already defined or declared Error 12 error C2535: 'void CXWindow::OnMouseDown(int,int,int)' : member function already defined or declared :doh: Ok! if I remove my override functions compiler says: Error 22 error C2259: 'CXWindow' : cannot instantiate abstract class d:\my codes\chess\chess\dx.cpp 16 :( Since I do not override them it says this is abstract! :wtf: Ok one more thing that i've noticed: OnRender method is also defined pure abstract but I do not get any error about that! Only difference is it does not contain any parameter and returns bool... :confused: thank you in advance...
-
Hey ppl, I got stuck with this pure thing.. I got a class which contains pure functions: virtual void OnMouseDown(int Button, int X, int Y) = NULL; virtual void OnMouseMove(int X, int Y) = NULL; virtual void OnMouseUp(int Button, int X, int Y) = NULL; virtual bool OnRender(void) = NULL; And I have a derived class which overrides these methods: bool OnRender(void); void OnMouseDown(int Button, int X, int Y); void OnMouseMove(int X, int Y); void OnMouseUp(int Button, int X, int Y); But the compiler says: Error 5 error C2535: 'void CXWindow::OnMouseDown(int,int,int)' : member function already defined or declared Error 6 error C2535: 'void CXWindow::OnMouseMove(int,int)' : member function already defined or declared Error 7 error C2535: 'void CXWindow::OnMouseUp(int,int,int)' : member function already defined or declared Error 12 error C2535: 'void CXWindow::OnMouseDown(int,int,int)' : member function already defined or declared :doh: Ok! if I remove my override functions compiler says: Error 22 error C2259: 'CXWindow' : cannot instantiate abstract class d:\my codes\chess\chess\dx.cpp 16 :( Since I do not override them it says this is abstract! :wtf: Ok one more thing that i've noticed: OnRender method is also defined pure abstract but I do not get any error about that! Only difference is it does not contain any parameter and returns bool... :confused: thank you in advance...
Some of the function names are the same as those used by MFC. Change the names and it should work.
«_Superman_» I love work. It gives me something to do between weekends.
-
Some of the function names are the same as those used by MFC. Change the names and it should work.
«_Superman_» I love work. It gives me something to do between weekends.
-
Hey ppl, I got stuck with this pure thing.. I got a class which contains pure functions: virtual void OnMouseDown(int Button, int X, int Y) = NULL; virtual void OnMouseMove(int X, int Y) = NULL; virtual void OnMouseUp(int Button, int X, int Y) = NULL; virtual bool OnRender(void) = NULL; And I have a derived class which overrides these methods: bool OnRender(void); void OnMouseDown(int Button, int X, int Y); void OnMouseMove(int X, int Y); void OnMouseUp(int Button, int X, int Y); But the compiler says: Error 5 error C2535: 'void CXWindow::OnMouseDown(int,int,int)' : member function already defined or declared Error 6 error C2535: 'void CXWindow::OnMouseMove(int,int)' : member function already defined or declared Error 7 error C2535: 'void CXWindow::OnMouseUp(int,int,int)' : member function already defined or declared Error 12 error C2535: 'void CXWindow::OnMouseDown(int,int,int)' : member function already defined or declared :doh: Ok! if I remove my override functions compiler says: Error 22 error C2259: 'CXWindow' : cannot instantiate abstract class d:\my codes\chess\chess\dx.cpp 16 :( Since I do not override them it says this is abstract! :wtf: Ok one more thing that i've noticed: OnRender method is also defined pure abstract but I do not get any error about that! Only difference is it does not contain any parameter and returns bool... :confused: thank you in advance...
dehseth wrote:
virtual void OnMouseDown(int Button, int X, int Y) = NULL; virtual void OnMouseMove(int X, int Y) = NULL; virtual void OnMouseUp(int Button, int X, int Y) = NULL; virtual bool OnRender(void) = NULL;
Pure virtual functions should be assigned
0
notNULL
. It's merely a coincidence thatNULL
has a value of0
."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons