저는 과제를 수행 중이며 특정 영역의 벽에 부딪혔습니다. 헤더에서 .cpp 파일로 비 멤버 함수를 구현하는 방법을 알아낼 수 없습니다. 여기 헤더입니다 :비 멤버 함수 구현
class complx
{
double real, imag;
public:
complx(double real = 0., double imag = 0.); // constructor
complx operator+(complx); // operator+()
complx operator+(double); // operator+()with double
complx operator- (complx); // operator-()
complx operator* (complx); // operator*()
bool operator== (complx); // operator==()
//Sets private data members.
void Set(double new_real, double new_imaginary) {
real = new_real;
imag = new_imaginary;
}
//Returns the real part of the complex number.
double Real() {
return real;
}
//Returns the imaginary part of the complex number.
double Imaginary() {
return imag;
}
};
ostream &operator << (ostream &out_file, complx number);
extern istream &operator >> (istream &in_file, complx &number);
extern ifstream &operator >> (ifstream &in_file, complx &number);
complx &operator + (double, complx);
complx &operator - (double, complx);
complx &operator * (double, complx);
}
내가 알아 낸 멤버의 대부분의 기능을 가지고 있지만, 그것은 나에게 맞는주는 헤더의 맨 아래에있는 세 가지입니다. 어떤 도움이라도 대단히 감사하겠습니다. 감사!
p.s. 서식을 미안합니다. 복사가 잘되지 않습니다. 당신의 .ccp 파일에서
한 가지 들어, 서명이 잘못되었습니다. 참조를 반환 할 임시 객체가 아닙니다. 값으로 대신 반환하십시오. –
탭을 찾아서 4 개의 공백으로 바꾸고 "코드 형식"버튼 ('{}) 아이콘을 붙여넣고 선택하고 누르십시오. –
솔직히 헤더 맨 아래에 6 개의 연산자 중 하나를 구현할 수 있다고 생각하지 않습니다. 예, 클래스에 연산자를 오버로드 할 수 있습니다. 아니요, 클래스없이 연산자를 오버로드 할 수 있다고 생각하지 않습니다 ... 실제로 수행하려고 시도한 것이면 ... – paulsm4