function in C++

Hi,
I am new to C++ and please help me with some problems.
Here is a code that I am confused.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
struct SFoo
{
   //...
};
 
class CFoo
{
   //...
};
 
void func1(SFoo foo) {/*...*/}
void func2(CFoo foo) {/*...*/}
void func3(SFoo& foo) {/*...*/}
void func4(CFoo& foo) {/*...*/}


Could you explain what is SFoo& and CFoo&?
Is there any difference between CFoo& foo and CFoo &foo?
func3 and func4 pass foo by reference, while func1 and func2 pass foo by value.
http://www.learncpp.com/cpp-tutorial/73-passing-arguments-by-reference/
http://www.learncpp.com/cpp-tutorial/72-passing-arguments-by-value/

Is there any difference between CFoo& foo and CFoo &foo

whitespace before or after the & makes no difference.
Thanks! These are great tutorials. I understand much more than just reading books.

whitespace before or after the & makes no difference

BTW, out of curiosity, why is that?
Last edited on
BTW, out of curiosity, why is that?
Because standard defines it that way.
As whitespaces do not make difference for operators: a+b ≈ a +b ≈ a+ b ≈ a + b; they do not matter when you would place * or &: int& a ≈ int &a ≈ int & a ≈ int&a
Last edited on
Thank you, MiiNiPaa.
I have no problem with whitespaces in a + b but int& a ≈ int &a ≈ int & a ≈ int&a are really new to me.
Really interesting!
Topic archived. No new replies allowed.