C++ function declaration argument handling
I'm a bit confused about a class method I'm using in a class template. the method was declared as so:
...
double getSlope(point& n)
...
so I assumed I would then need to pass a point by reference to the method:
double d=b.getSlope(&a);
//but when I call it like that, I get the following errors:
/*
error: no matching function for call to 'point<double>::middle(point<double>*)'
note: candidates are: point<Tn> point<Tn>::middle(point<Tn>&) [with Tn = double]
*/
without the ampersand, however, it compiles and runs properly. would it be more correct like this:
...
double getSlope(point n)...
//and then call the method like this:
double d=b.getSlope(&a);
or does it still pass by reference because it was declared to pass by reference? or am I just completely not understanding something?
I may still be a bit confused, but isn't it a bit faster to pass the address of an object, rather that just use the object's identifier as the argument, and have the entire value of the object copied to the function? it may not make much of a difference in my program, so I guess it really doesn't matter. I guess what I'm really asking is would this:
int someFunction(object& a){
...}
someFunction(a);
//be, essentially, the same as this:
int someFunction(object a){
..}
someFunction(&a);
Edit: nevermind, I found my answer here: http://www.linuxquestions.org/questions/programming-9/c-passing-a-variable-by-reference-to-a-class-member-function.-383445/ and they are the same for my purposes.