Jump to content
  • Advertisement
Sign in to follow this  
VillageIdiot

c++ class as paramater from within the class

This topic is 3596 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I tried a few times to put this into words, none of them made any sense. Basically, I am trying to call a function with a class parameter, the catch is the class being passed is the class I am calling it in. Here is a code example (I know the code doesn't work, this is a quick example)
class a
{
   int x,y,func(template);
}

int a::func(template obj)
{
   //do stuff
}

class b
{
   int function(a)
}
int b::function(a obj)
{
   a(this);
}
I am unable to pass "this" to the function, it tells me this every time I try to access something: error: request for member `x' in `obj', which is of non-class type `player*' x being the member, obj being the parameter name, and player being the class that is being passed. How would do this?

Share this post


Link to post
Share on other sites
Advertisement
By passing the correct parameter?

this is a pointer type. Your arguments (as you describe them) are not. Either dereference the pointer or make the method take a pointer.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!