Original Post
I have that:
Im calling a function of the same namespace as the class, inside a member of the class, and that function take that class reference as arguments, im trying to make that work and put the declaration of class and external function on the top, so they are know in the rest of the file, but i still get errors, like this one:
multiple definition of `NS::Func(NS::Foo const&, NS::Foo const&)'|
How that can be done right ?
#ifndef _FOO_H_
#define _FOO_H_
namespace NS {
class Foo;
float Func(const Foo& f1,const Foo& f2);
class Foo {
public:
float a,b;
Foo() {};
Foo(float n1,float n2):a(n1),b(n2) { };
Foo(const Foo& foo):a(foo.a),b(foo.b) { };
~Foo() {};
const Foo& operator = (const Foo& foo) {
a = foo.a;
b = foo.b;
return *this;
}
const Foo& operator * (const Foo& foo) {
a *= foo.a;
b *= foo.b;
return *this;
}
// Here float NS::Func(const NS::Foo&,const NS::Foo&) is known?
float Func(const Foo& foo) {
return NS::Func(*this,foo);
}
};
float Func(const Foo& f1,const Foo& f2) {
return f1.a*f2.a + f1.b*f2.b;
}
}; // namespace end
#endif
Im calling a function of the same namespace as the class, inside a member of the class, and that function take that class reference as arguments, im trying to make that work and put the declaration of class and external function on the top, so they are know in the rest of the file, but i still get errors, like this one:
multiple definition of `NS::Func(NS::Foo const&, NS::Foo const&)'|
How that can be done right ?