Sign in to follow this  

c++ class as paramater from within the class

This topic is 3382 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
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

This topic is 3382 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this