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

Operator Overloading

Scheduled Pinned Locked Moved C / C++ / MFC
question
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.
  • R Offline
    R Offline
    RichardS
    wrote on last edited by
    #1

    Hi All, I have a structure that contains a list of function delegates. Each of the delegates do something different. Depending on how the parent class is initialised, depends on which of delegates is populated. Now the question is, can I overload the '->' operator, so that the calling code can call one of the delegates in the structure by calling the same name. e.g.

    class X { struct y { fastdelegate someMemberDelegateOfY; ... } ... }
    {
     X myX;
     myX->someMemberDelegateOfY (parameters,for,delegate,in,struct,y);
    }
    

    Then when the code executes, it will call the delegate in the structure. Is this possible, and if so how? thanks, Rich

    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far the Universe is winning." -- Rich Cook

    V Z 2 Replies Last reply
    0
    • R RichardS

      Hi All, I have a structure that contains a list of function delegates. Each of the delegates do something different. Depending on how the parent class is initialised, depends on which of delegates is populated. Now the question is, can I overload the '->' operator, so that the calling code can call one of the delegates in the structure by calling the same name. e.g.

      class X { struct y { fastdelegate someMemberDelegateOfY; ... } ... }
      {
       X myX;
       myX->someMemberDelegateOfY (parameters,for,delegate,in,struct,y);
      }
      

      Then when the code executes, it will call the delegate in the structure. Is this possible, and if so how? thanks, Rich

      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far the Universe is winning." -- Rich Cook

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      function pointer correct as is X x (x.*p)() Kuphryn

      1 Reply Last reply
      0
      • R RichardS

        Hi All, I have a structure that contains a list of function delegates. Each of the delegates do something different. Depending on how the parent class is initialised, depends on which of delegates is populated. Now the question is, can I overload the '->' operator, so that the calling code can call one of the delegates in the structure by calling the same name. e.g.

        class X { struct y { fastdelegate someMemberDelegateOfY; ... } ... }
        {
         X myX;
         myX->someMemberDelegateOfY (parameters,for,delegate,in,struct,y);
        }
        

        Then when the code executes, it will call the delegate in the structure. Is this possible, and if so how? thanks, Rich

        "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far the Universe is winning." -- Rich Cook

        Z Offline
        Z Offline
        Zac Howland
        wrote on last edited by
        #3

        RichardS wrote:

        Is this possible, and if so how?

        Yes.

        class X
        {
        public:
                int getInt() { return 0; }
        };
        
        class Y
        {
        public:
                X* operator->() { return &_x; }
        private:
                X _x;
        };
        
        int main()
        {
                Y y;
                return y->getInt();
        }
        

        The restriction on overloading -> is that it must return a pointer of some kind.

        If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

        R 1 Reply Last reply
        0
        • Z Zac Howland

          RichardS wrote:

          Is this possible, and if so how?

          Yes.

          class X
          {
          public:
                  int getInt() { return 0; }
          };
          
          class Y
          {
          public:
                  X* operator->() { return &_x; }
          private:
                  X _x;
          };
          
          int main()
          {
                  Y y;
                  return y->getInt();
          }
          

          The restriction on overloading -> is that it must return a pointer of some kind.

          If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

          R Offline
          R Offline
          RichardS
          wrote on last edited by
          #4

          Thanks, works great :) Rich

          "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far the Universe is winning." -- Rich Cook

          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