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. C++ Classes (problem with events)

C++ Classes (problem with events)

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++help
4 Posts 4 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.
  • M Offline
    M Offline
    marcio k
    wrote on last edited by
    #1

    I'm writing a windows socket wrapper class in c++ from scratch and i cannot get events to work. So inside the class i'll have several events. let's pretend i have the following class:

    class SocketTree
    {
    public:
    int Close();

    virtual void OnClose(); //*this will be the event
    }

    SocketTree::Close()
    {
    OnClose();
    return 0;
    }

    And now i'll have the derived class that will receive the event:

    class SckHandle : public SocketTree
    {
    public:
    virtual void OnClose();
    }

    SckHandle::OnClose()
    {
    printf("working.");
    }

    And here's the main procedure:

    int main()
    {
    SckHandle sHnd;
    sHnd.Close();
    return 0;
    }

    when sHand.Close() is executed, i wanted the event OnClose() to be fired, but it won't... anyone knows what is happening in here and what should i do to handle events correctly? thank you :)

    A K 2 Replies Last reply
    0
    • M marcio k

      I'm writing a windows socket wrapper class in c++ from scratch and i cannot get events to work. So inside the class i'll have several events. let's pretend i have the following class:

      class SocketTree
      {
      public:
      int Close();

      virtual void OnClose(); //*this will be the event
      }

      SocketTree::Close()
      {
      OnClose();
      return 0;
      }

      And now i'll have the derived class that will receive the event:

      class SckHandle : public SocketTree
      {
      public:
      virtual void OnClose();
      }

      SckHandle::OnClose()
      {
      printf("working.");
      }

      And here's the main procedure:

      int main()
      {
      SckHandle sHnd;
      sHnd.Close();
      return 0;
      }

      when sHand.Close() is executed, i wanted the event OnClose() to be fired, but it won't... anyone knows what is happening in here and what should i do to handle events correctly? thank you :)

      A Offline
      A Offline
      andersod2
      wrote on last edited by
      #2

      should give a linker error -- SocketTree::OnClose was not defined...if you define it, it will probably work properly. If it is not your intention to have a valid OnClose for SocketTree, then you could declare it as pure virtual by putting a "= 0;" at the end. But then the class is pure virtual, so you can't instantiate objects of that type, only derived objects. Technically speaking, you should also have a "using SocketTree::Close()" as part of your derived class's public area if you intend to use base class functions from your derived objects. Most people probably wouldn't do that I'm guessing, but it is more accurate.

      V 1 Reply Last reply
      0
      • M marcio k

        I'm writing a windows socket wrapper class in c++ from scratch and i cannot get events to work. So inside the class i'll have several events. let's pretend i have the following class:

        class SocketTree
        {
        public:
        int Close();

        virtual void OnClose(); //*this will be the event
        }

        SocketTree::Close()
        {
        OnClose();
        return 0;
        }

        And now i'll have the derived class that will receive the event:

        class SckHandle : public SocketTree
        {
        public:
        virtual void OnClose();
        }

        SckHandle::OnClose()
        {
        printf("working.");
        }

        And here's the main procedure:

        int main()
        {
        SckHandle sHnd;
        sHnd.Close();
        return 0;
        }

        when sHand.Close() is executed, i wanted the event OnClose() to be fired, but it won't... anyone knows what is happening in here and what should i do to handle events correctly? thank you :)

        K Offline
        K Offline
        KarstenK
        wrote on last edited by
        #3

        Dig stepwise with Debugger in it and you will see that you call SocketTree::OnClose(). Write in class SocketTree: virtual void OnClose() = 0;

        Greetings from Germany

        1 Reply Last reply
        0
        • A andersod2

          should give a linker error -- SocketTree::OnClose was not defined...if you define it, it will probably work properly. If it is not your intention to have a valid OnClose for SocketTree, then you could declare it as pure virtual by putting a "= 0;" at the end. But then the class is pure virtual, so you can't instantiate objects of that type, only derived objects. Technically speaking, you should also have a "using SocketTree::Close()" as part of your derived class's public area if you intend to use base class functions from your derived objects. Most people probably wouldn't do that I'm guessing, but it is more accurate.

          V Offline
          V Offline
          Varghese Paul M
          wrote on last edited by
          #4

          I fully agree with the above reply. Just one update. The brackets are not allowed with the "using" keyword. using SocketTree::Close; is Ok. Normally this statement is not required.

          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