basic declaring and function passing questions

Very beginners questions, but my lack of good c++ knowledge letting me down.

Problem 1)

So I have this…

// .h declare  
ofCvGrayscaleImage * myImage;  
// .cpp setup  
myImage.allocate(320, 240);  

For some reason this is now tripping up when I build.

error C2228: left of ‘.allocate’ must have class/struct/union
type is ‘ofCvGrayscaleImage *’
did you intend to use ‘->’ instead?

I am using this in my own class, but I am including ofCvGrayscaleImage.h so it should work, as this works in other class I have.

Problem 2)

If I want to pass an image into my own class, what is the difference between using these three and which should I actually use:

void myFunction(ofCvGrayscaleImage _tempimage);  
void myFunction(ofCvGrayscaleImage & _tempimage);  
void myFunction(ofCvGrayscaleImage * _tempimage);  


hi –

for problem 1,


ofCvGrayscaleImage myImage;  
// .cpp setup  
myImage.allocate(320, 240);   

(if it’s a pointer, you need to write it like this)

ofCvGrayscaleImage * myImage;  
// .cpp setup  
myImage = new ofCvGrayscaleImage ();  
myImage->allocate(320, 240);   

but it’s typically easier to not use a pointer.

for problem 2:

What you are interested in looking at is “pass by reference” vs “pass by value”

some info:±faq-lite/r-…-ml#faq-8.1…-ml#RTFToC6

but the question (which is better) is answered by knowing what you would like to do with the function. can you write a brief description ?

take care!!