Jump to content
AnthonyPython

why &World::Clear; in C++?

Recommended Posts

to go into but more explanation of what question I am asking is, why does

&World::Clear; 

 

work instead of

World::Clear;

Intelleasense said to put a & in front but why does it not work without a & symbol?

Share this post


Link to post

Neither of them will work.

 

First of all you have to have an instance of the world

and then use the methods (functions) on that instance

 

World* myWorld = World::Create();
myWorld->Clear();

Share this post


Link to post

Neither of them will work.

 

First of all you have to have an instance of the world

and then use the methods (functions) on that instance

 

World* myWorld = World::Create();
myWorld->Clear();

 

Intellasense does some strange stuff some times. :/

Share this post


Link to post

& (ampersand if you want to google it ;) ) has 2 functions in C++

  1. When used during declaration of a variable it means said variable is a reference - that is any change made to it is made to the original also;
  2. When used infront of an existing variable it takes the address of the object ( effectively turning it into a pointer )

Share this post


Link to post

& (ampersand if you want to google it wink.png ) has 2 functions in C++

  1. When used during declaration of a variable it means said variable is a reference - that is any change made to it is made to the original also;
     
  2. When used infront of an existing variable it takes the address of the object ( effectively turning it into a pointer )

 

 

ah ok

 

You might also want to read up on C++ pointers.

http://www.cplusplus.com/doc/tutorial/pointers/

 

whoa, that is a ton of info on pointer's xD (also btw I did

 world->Clear();

first but then intellesense wanted me to put &World::Clear; instead, Clearly I know that wasn't correct.)

Share this post


Link to post

I did

 world->Clear();

first but then intellesense wanted me to put &World::Clear; instead, Clearly I know that wasn't correct.

 

It suggests that you either accidentally used uppercase for world (World) or that the variable "world" was not in scope.

Share this post


Link to post

It suggests that you either accidentally used uppercase for world (World) or that the variable "world" was not in scope.

Yea I used World instead, anyways though thanks for the cool info Guppy as usual wink.png

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...