안녕 얘들 아 나는 학습 연산자 오버로드를하고 연습을 위해 복소수를 추가하는 코드를 작성하고있었습니다.미완성 유형을 정의 할 수 없습니다.
는 내가 제대로 모든 단계를 완료 한 것처럼 보이지만 주에 난 내 클래스의 객체를 만들 때 다음 나는
E:\Opp\Practice\ComplexNumbers\main.cpp|9|error: aggregate 'Complex c2' has incomplete type and cannot be defined|
E:\Opp\Practice\ComplexNumbers\main.cpp|9|error: variable 'Complex c2' has initializer but incomplete type|
당신은 내 코드에서보세요 수 있다고
#include <iostream>
using namespace std;
class Complex;
int main()
{
Complex c1(10,20),c2(30,40),c3;
c3=c1+c2;
c3.Display();
return 0;
}
class Complex
{
public:
Complex();
Complex(int,int);
void setReal(int);
void setImaginary(int);
int getReal();
int getImaginary();
Complex operator + (Complex);
void Display();
private:
int real , imaginary;
};
Complex::Complex()
{
real = 0;
imaginary =0;
}
Complex::Complex(int r , int i)
{
real = r;
imaginary =i;
}
Complex Complex:: operator +(Complex num1)
{
Complex temp;
temp.real = num1.real + real;
temp.imaginary=num1.imaginary + imaginary;
return temp;
}
void Complex :: Display()
{
cout << "Real " << real << "Imaginary " << imaginary << endl;
}
int Complex ::getReal()
{
return real;
}
int Complex ::getImaginary()
{
return imaginary;
}
void Complex ::setReal(int r)
{
real = r;
}
void Complex::setImaginary(int i)
{
imaginary = i;
}
그래, 고마워하지만 제발 더 설명해주세요 ... –
내가 더 설명하기 위해 내 게시물을 편집하기 전에이 코멘트를 썼다고 생각합니다. 현재의 설명이 충분하지 않습니까? – jpo38
예 고마워요. 당신의 포인트를 얻었습니다. 당신이 축복 해 주신 하나님 : –