Click here to Skip to main content
15,912,072 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
So i have class that holds inside a pointer to an object i want to use an acessor to retrive the value for example:

class Example{
private:
Pointing* aPointer;

public:
Example(Pointing* point){
aPointer = point;
}

int acessor(){
return aPointer->exampleMethod();
}


};


when compiling i receive an error anyone have any ideas
Posted

1 solution

You need to tell us what the error is. We can't read your mind. Then, your acessor (sic) should check first if the pointer is null. But, all of that should compile. I can't see why this would not compile, unless Pointer does not have an 'exampleMethod'.
 
Share this answer
 
Comments
diego14567 9-Nov-13 15:24pm    
the error says Pointing::exampleMethod missing argument list use &Pointing::exampleMethod to create a pointer to member
Christian Graus 9-Nov-13 15:26pm    
So that sounds like the exampleMethod takes arguments, to me. Can you post the code to the Pointing class ?
diego14567 9-Nov-13 15:32pm    
so inside pointing there is a method called exampleMethod

int exampleMethod(){
return value;
}

value is just a instance field with a value passed in from the constructor

Pointing(int n){
value = n;
}
Christian Graus 9-Nov-13 15:35pm    
Do you have a #include in your Example class so that it knows what Pointing is ?
diego14567 9-Nov-13 15:44pm    
yes theres the include from the header file

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900