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 for casting a class to void*

Operator for casting a class to void*

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
5 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.
  • K Offline
    K Offline
    kfaday
    wrote on last edited by
    #1

    Hi, i would like to know hot to implement an operator to cast a class to void*. I thought of overloading operator (), but i don't know how to proceed (as i didn't find anything on the web). Any ideas? thanks!!

    4 D 2 Replies Last reply
    0
    • K kfaday

      Hi, i would like to know hot to implement an operator to cast a class to void*. I thought of overloading operator (), but i don't know how to proceed (as i didn't find anything on the web). Any ideas? thanks!!

      4 Offline
      4 Offline
      4apai
      wrote on last edited by
      #2

      The following example overloads the + operator to add two complex numbers and returns the result. // operator_overloading.cpp // compile with: /EHsc #include using namespace std; class Complex { public: Complex( double r, double i ) : re(r), im(i) {} Complex operator+( Complex &other ); void Display( ) { cout << re << ", " << im << endl; } private: double re, im; }; // Operator overloaded using a member function Complex Complex::operator+( Complex &other ) { return Complex( re + other.re, im + other.im ); } int main() { Complex a = Complex( 1.2, 3.4 ); Complex b = Complex( 5.6, 7.8 ); Complex c = Complex( 0.0, 0.0 ); c = a + b; c.Display(); }

      1 Reply Last reply
      0
      • K kfaday

        Hi, i would like to know hot to implement an operator to cast a class to void*. I thought of overloading operator (), but i don't know how to proceed (as i didn't find anything on the web). Any ideas? thanks!!

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

        Something like:

        class MyClass
        {
        public:
        operator LPVOID() const
        {
        return ???;
        }
        };


        "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

        K 1 Reply Last reply
        0
        • D David Crow

          Something like:

          class MyClass
          {
          public:
          operator LPVOID() const
          {
          return ???;
          }
          };


          "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

          K Offline
          K Offline
          kfaday
          wrote on last edited by
          #4

          what do you mean with ??? thanks!

          D 1 Reply Last reply
          0
          • K kfaday

            what do you mean with ??? thanks!

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

            Since you did not tell us anything about your class, I obviously don't know what that method needs to return.


            "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

            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