0
나는 클래스의 private 멤버를 사용하고 있다는 이상한 알림을 받는다. 이것은 전적으로 유효하지만, 그렇게 할 수는 있지만, 메소드 I 사용하는 것은 친근한 것입니다.클래스의 내 멤버 -이 컨텍스트 내
#include <iostream>
using namespace std;
class complex {
private:
double Re, Im;
public:
complex(): Re(0.0), Im(0.0){}
complex(double Re, double Im): Re(Re), Im(Im){}
double getRe() const { return Re; }
double getIm() const { return Im; }
friend complex operator+(const complex&, const complex&);
friend ostream& operator<<(ostream&, const complex&);
friend istream& operator>>(istream &, const complex &); // FRIENDLY FUNCTION
};
complex operator+(const complex& a, const complex& b) {
double r, i;
r = a.getRe()+ b.getRe();
i = a.getIm() + b.getIm();
return complex(r, i);
}
ostream& operator<<(ostream& out, const complex &a) {
out << "(" << a.getRe() << ", " << a.getIm() << ")" << endl;
return out;
}
istream &operator>>(istream &in, complex &c)
{
cout<<"enter real part:\n";
in>>c.Re; // ** WITHIN THIS CONTEXT ERROR **
cout<<"enter imag part: \n";
in>>c.Im; // ** WITHIN THIS CONTEXT ERROR **
return in;
}
int main(void) {
complex a, b,c;
cin >> a;
cin >> b;
c = a+b;
cout << c;
}
나는 민간있는 값을 얻기 위해 클래스 내에서 setFunction의 일종을 선언해야합니다 :
이 한 번 봐?
거기 해왔다. 여전히 정확히 같은 오류가 발생합니다. ( –