S
Spoon
Hello,
Consider the following code:
int foo(int n) { return n+2; }
class bar
{
public:
int x;
bar() { x = 42; }
int foo() { return foo(x); }
};
int main()
{
bar baz;
return baz.foo();
}
Apparently this doesn't work.
test.cpp: In member function `int bar::foo()':
test.cpp:8: error: no matching function for call to `bar::foo(int&)'
test.cpp:8: note: candidates are: int bar::foo()
I was told that the original foo lives in the unnamed namespace, and I
that I could refer to that function with ::foo
int foo(int n) { return n+2; }
class bar
{
public:
int x;
bar() { x = 42; }
int foo() { return ::foo(x); }
};
int main()
{
bar baz;
return baz.foo();
}
Is that how it's usually done? Are there other/better ways?
Do I need to place my helper functions in a specific namespace?
Regards.
Consider the following code:
int foo(int n) { return n+2; }
class bar
{
public:
int x;
bar() { x = 42; }
int foo() { return foo(x); }
};
int main()
{
bar baz;
return baz.foo();
}
Apparently this doesn't work.
test.cpp: In member function `int bar::foo()':
test.cpp:8: error: no matching function for call to `bar::foo(int&)'
test.cpp:8: note: candidates are: int bar::foo()
I was told that the original foo lives in the unnamed namespace, and I
that I could refer to that function with ::foo
int foo(int n) { return n+2; }
class bar
{
public:
int x;
bar() { x = 42; }
int foo() { return ::foo(x); }
};
int main()
{
bar baz;
return baz.foo();
}
Is that how it's usually done? Are there other/better ways?
Do I need to place my helper functions in a specific namespace?
Regards.