次のコードは、Visual Studio 2012 Express、Windows 8 で正常にコンパイルされます
しかし、私の好みのプラットフォームである Eclipse Juno では、OS XI 上の GCC 4.2 は次のエラーを受け取ります。
../src/Test.cpp:20: エラー: '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()
{
}
どんな支援も最も役に立ちます。学校のプロジェクトの課題に取り組んでいます。