Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: understanding noncopyable objects  (Read 1474 times)

0 Members and 1 Guest are viewing this topic.

HammaJamma

  • Newbie
  • *
  • Posts: 12
    • View Profile
understanding noncopyable objects
« on: May 24, 2014, 03:31:51 am »
Hello  :D
I've been learning C++ and I use SFML for a more engaging learning experience than just outputting text to the console. unfortunately, at times, my use of SFML extends past my knowledge of C++. Normally I just go back to reading a couple books that I have or I search the internet until i have a better understanding of C++ but this last problem I've ran into has me stumped because I don't really know what to search. I'm hoping someone out there can give me some specific terminology about this piece of code so I know what to google/what chapter I should be reading out of.
the problem started when i began passing "noncopyable" objects into functions, so I began researching the error I was getting and came across many pieces of code similar to the following.

changeWindow(sf::RenderWindow &window) : mainWindow(&window)
{
    mainWindow -> window;
}

I have a basic understanding of passing objects by reference and using pointers but what I really don't understand is, what the heck is that colon and the "->" doing or what it's called?

In short, can someone please give me some direction for research so I can understand the above code?

math1992

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
    • Email
Re: understanding noncopyable objects
« Reply #1 on: May 24, 2014, 04:35:08 am »

changeWindow(sf::RenderWindow &window) : mainWindow(&window)
{
    mainWindow -> window;
}
 

I have a basic understanding of passing objects by reference and using pointers but what I really don't understand is, what the heck is that colon and the "->" doing or what it's called?


In short

mainWindow -> window;

//is equivalent to

(*mainWindow).window
 

To explain it in simple words the -> access what is pointed by a pointer. Search pointer on the net for clear detail (Or check official C++ website). Also, the colon is related to constructor and is a common way to initialize attributes. So search "C++ constructor" on the net...




« Last Edit: May 24, 2014, 05:50:27 am by math1992 »

HammaJamma

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: understanding noncopyable objects
« Reply #2 on: May 25, 2014, 01:57:16 am »
Thank you for the quick reply. Back to reading :)

 

anything