class object pointer access methods?

Apr 9, 2012 at 5:45am
I am writing code and I am using a pointer to point to an object of a class I created. I want to have this pointer run a method, but I am getting an error of:
request for member 'ClassMethod' in 'ptr', which is of non-class type

Essentially my main code (at the error) is this:
1
2
void MyFunction(Object * ptr)
{*ptr.ClassMethod(true);}

and the method in the class:
1
2
void Object::ClassMethod(bool var)
{/*execute code*/}

How would do this?
Apr 9, 2012 at 5:49am
Try:
1
2
3
ptr->ClassMethod
//or more verbose:
(*ptr).ClassMethod
Apr 9, 2012 at 5:49am
Your error is happening due to the order of operations. The member access is coming before the dereference so you're trying to do the member access on the pointer.

Some brackets will help:

(*ptr).ClassMethod(true);

(or equivalently)

ptr->ClassMethod(true);
Apr 9, 2012 at 5:32pm
Thanks, that worked.
Topic archived. No new replies allowed.