以下代码在 Visual Studio 2012 Express、Windows 8 下编译得很好
但在我首选的平台上,Eclipse Juno,OS XI 上的 GCC 4.2 收到以下错误:
../src/Test.cpp:20: error: 'std::istream& TestNS::operator>>(std::istream&, TestNS::Test&)' 应该在'TestNS'中声明
#include <cstdio>
#include <cstdlib>
#include <iostream>
using std::istream;
namespace TestNS
{
class Test
{
friend istream &operator>>(istream &in, Test &value);
public:
Test(double real, double image);
private:
double real;
double image;
void initialize(double real, double image);
};
}
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include "Header.h"
using std::istream;
using namespace TestNS;
TestNS::Test::Test(double real = 0.0, double image = 0.0) : real(real), image(image)
{
}
void TestNS::Test::initialize(double real, double image)
{
this->real = real;
this->image = image;
}
istream& TestNS::operator>> (istream &in, TestNS::Test &value)
{
value.real = 10.0;
value.image = 10.0;
return in;
}
int main()
{
}
任何帮助都是最有帮助的。为学校项目工作。