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
wpfwcfhelpquestion
3 Posts 2 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.
  • X Offline
    X Offline
    Xian
    wrote on last edited by
    #1

    Here is my problem! I have three classes set up sort of like this: class MainClass { CSocketClass * pSock; // instance of my socket class. } class CSocketClass { CSocketAddr * pObj; }; class CSocketAddr { operator LPSOCKADDR() { return ( LPSOCKADDR )( LPSOCKADDR_IN )this; } } When I call my MainObject->pSock->bind() [which uses my LPSOCKADDR override] and try to do some binding, the pointer this does not refer to the class I called it from, it points back to my main object! That is bunk! When I say "this" I want the class I am calling in. Is it just me? Peace. ---- Xian

    T 1 Reply Last reply
    0
    • X Xian

      Here is my problem! I have three classes set up sort of like this: class MainClass { CSocketClass * pSock; // instance of my socket class. } class CSocketClass { CSocketAddr * pObj; }; class CSocketAddr { operator LPSOCKADDR() { return ( LPSOCKADDR )( LPSOCKADDR_IN )this; } } When I call my MainObject->pSock->bind() [which uses my LPSOCKADDR override] and try to do some binding, the pointer this does not refer to the class I called it from, it points back to my main object! That is bunk! When I say "this" I want the class I am calling in. Is it just me? Peace. ---- Xian

      T Offline
      T Offline
      Todd Smith
      wrote on last edited by
      #2

      What does you bind function look like?

      Todd Smith

      X 1 Reply Last reply
      0
      • T Todd Smith

        What does you bind function look like?

        Todd Smith

        X Offline
        X Offline
        Xian
        wrote on last edited by
        #3

        void XSocket::bindAddress()
        {
        if( ::bind( m_hSocket, ( LPSOCKADDR )m_pAddress, sizeof( SOCKADDR ) ) == SOCKET_ERROR )
        throw "bindAddress";
        }

        Well, not anymore...:-D I got around this by not overloading operators and calling member funcs explicitly. It still p1ss3s me off though! I think the "this" pointer within a class should reference the class it is within. Peace. ---- Xian

        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