Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Pure Functions..

Pure Functions..

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dehseth
    wrote on last edited by
    #1

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

    _ D 2 Replies Last reply
    0
    • D dehseth

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

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      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.

      D 1 Reply Last reply
      0
      • _ _Superman_

        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.

        D Offline
        D Offline
        dehseth
        wrote on last edited by
        #3

        wow you are totaly right... :thumbsup: i did change their names and it worked... :-D i do not use MFC in my app but still I add windows.h, windowsx.h.. :^) anyways... thank you very much.. :)

        1 Reply Last reply
        0
        • D dehseth

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

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          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 not NULL. It's merely a coincidence that NULL has a value of 0.

          "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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups