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. Difference between "->" and "."

Difference between "->" and "."

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

    I have some experience programming in C# .NET but am new to C++. Could somebody please tell me what the difference between "->" and "." are in C++, which is to say: when is it appropriate to use someclass.whatever and when is it correct to use someclass->whatever. Thanks!

    C L W 3 Replies Last reply
    0
    • C crushinghellhammer

      I have some experience programming in C# .NET but am new to C++. Could somebody please tell me what the difference between "->" and "." are in C++, which is to say: when is it appropriate to use someclass.whatever and when is it correct to use someclass->whatever. Thanks!

      C Offline
      C Offline
      crushinghellhammer
      wrote on last edited by
      #2

      Nevermind, I found it in the documentation. Thanks anyway!

      1 Reply Last reply
      0
      • C crushinghellhammer

        I have some experience programming in C# .NET but am new to C++. Could somebody please tell me what the difference between "->" and "." are in C++, which is to say: when is it appropriate to use someclass.whatever and when is it correct to use someclass->whatever. Thanks!

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        crushinghellhammer wrote: someclass.whatever CSomeClass myClass; myClass.whatever; crushinghellhammer wrote: someclass->whatever CSomeClass *myClass; myClass->whatever; The "." operator is used to directly access the object's members. Artificial intelligence is no match for natural stupidity.

        1 Reply Last reply
        0
        • C crushinghellhammer

          I have some experience programming in C# .NET but am new to C++. Could somebody please tell me what the difference between "->" and "." are in C++, which is to say: when is it appropriate to use someclass.whatever and when is it correct to use someclass->whatever. Thanks!

          W Offline
          W Offline
          weblee
          wrote on last edited by
          #4

          -> dereferences a class object pointer. SomeClass { public : int a; }; So if you have SomeClass *oSomeClass = new oSomeClass(); Accessing member variable a is done by first dereferencing the pointer and using the '.'operator: (*oSomeClass).a = 5; which is equivalent to the statement oSomeClass->a = 5;

          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