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

Overload -> operator

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++comgraphics
4 Posts 3 Posters 1 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.
  • _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #1

    I saw here: Flicker Free Drawing In MFC[^] in MemDC source code a line:

    // Allow usage as a pointer	
    CMemDC\* operator->() 
    {
    	return this;
    }
    

    Sorry for this simple question: it was really necessary ? If I have an already pointer to an CMemDC object, and I write pMemDC->, then is not the same thing like this operator didn't has been overloaded ? Thank you for any clarifying !

    J A 2 Replies Last reply
    0
    • _ _Flaviu

      I saw here: Flicker Free Drawing In MFC[^] in MemDC source code a line:

      // Allow usage as a pointer	
      CMemDC\* operator->() 
      {
      	return this;
      }
      

      Sorry for this simple question: it was really necessary ? If I have an already pointer to an CMemDC object, and I write pMemDC->, then is not the same thing like this operator didn't has been overloaded ? Thank you for any clarifying !

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      It is the same if you already have a pointer. But that class is usually created as

      CMemDC pDC(dc);

      where you don't have a pointer. The reason for the overload is that the class is used instead of the CDC* which is passed to the drawing functions. So you can modify existing code for the CDC* by just replacing the variable name without changing the access operator from -> to .. Using such is bad practice but has been used by MFC too. It makes sense for this special class but should be generally avoided.

      _ 1 Reply Last reply
      0
      • J Jochen Arndt

        It is the same if you already have a pointer. But that class is usually created as

        CMemDC pDC(dc);

        where you don't have a pointer. The reason for the overload is that the class is used instead of the CDC* which is passed to the drawing functions. So you can modify existing code for the CDC* by just replacing the variable name without changing the access operator from -> to .. Using such is bad practice but has been used by MFC too. It makes sense for this special class but should be generally avoided.

        _ Offline
        _ Offline
        _Flaviu
        wrote on last edited by
        #3

        Ok, I get it. Thank you.

        1 Reply Last reply
        0
        • _ _Flaviu

          I saw here: Flicker Free Drawing In MFC[^] in MemDC source code a line:

          // Allow usage as a pointer	
          CMemDC\* operator->() 
          {
          	return this;
          }
          

          Sorry for this simple question: it was really necessary ? If I have an already pointer to an CMemDC object, and I write pMemDC->, then is not the same thing like this operator didn't has been overloaded ? Thank you for any clarifying !

          A Offline
          A Offline
          Andy Bantly
          wrote on last edited by
          #4

          I think I can help but I am struggling with the grammar and intent of your question. -> operator gives you access to the class. It is much like operator .

          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