Follow us on Twitter!
Don't judge the unknown - Grindordie
Wednesday, April 23, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 26
Guests Online: 24
Members Online: 2

Registered Members: 82877
Newest Member: MWiki
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

C++ function declaration argument handling


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 17-09-09 15:29
I'm a bit confused about a class method I'm using in a class template. the method was declared as so:
Code

...
double getSlope(point& n)
...




so I assumed I would then need to pass a point by reference to the method:
Code

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:
Code

...
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?
Author

RE: C++ function declaration argument handling

ynori7
Member



Posts: 1486
Location: #valhalla
Joined: 08.10.07
Rank:
God
Posted on 17-09-09 15:57
Do you have some need for pointers? Because if you don't, it's easier to not use them.

And you're best way to figure out what's going wrong would be to read a few explanations about how pointers work and pointer arithmetic.


halls-of-valhalla.org/images/affiliateLogo.png voodoorage.halls-of-valhalla.org/images/smallLogo.png
i537.photobucket.com/albums/ff338/ynori77/archenemysig1.jpg
ynori7 http://halls-of-valhalla.org
Author

RE: C++ function declaration argument handling


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 17-09-09 16:13
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:
Code

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.linuxq. . .n.-383445/
and they are the same for my purposes.

Edited by on 17-09-09 17:00