So, pointers as arguments. How do I do this?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Coming from a C# XNA background for the past year of university, Im used to passing objects as arguments to make comparisons and changes to them. Im reading "Sams teach yourself C++ in 24 hours" and Im programming a physics engine as I go.
In XNA I would declare an object with the new keyword, and then I can make changes, pass the object to functions and make comparisons just by using the objects name followed by dot parameter or function call.
In C++ you can do the same thing, but when you use pointers it changes and they work differently. What I want to know is how do I pass a pointer as a argument in C++?
I know that I can pass the address of an object,
<pre class="prettyprint &objectName[/code]
<br/>
but I havent got an any declared yet, Ive just been using pointers.
<pre class="prettyprint GameObject * pGameObj;[/code]
<br/>
If I do declare an object and then point to its address I get a C2512 error. Which I gather is because my GameObject class is a child of a ParticleModel, and so that would be an issue with my constructor (which Im not entirely sure how to fix yet)
My pointer is initialized using the new keyword, as you would. But I cant just simply pass the pointer to a function like I would an object from what I can tell, and that is what I would like to do.
How do I resolve this? If I stick to the pointer I dont know how to resolve it, if I try to declare an object to instead point, because then for the sake of functions I can just pass the address of the object, then I get the C2512 error and I havent a
clue on how to resolve it.

If you need to see my code then thats fine, but I dont think that would be neccessary just some help opening up some options and solutions. <hr class="sig Second Year Programming Student - UK

View the full article
 
Back
Top