게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
C++ 복소수 오버로딩 오류 도와주세요 ㅠ
게시물ID : programmer_16987짧은주소 복사하기
작성자 : Do잇
추천 : 0
조회수 : 495회
댓글수 : 2개
등록시간 : 2016/04/28 21:53:03
옵션
  • 본인삭제금지

#include<iostream>

using namespace std;

class complex
{
public:
 complex(double real = 0, double image =0);
 ~complex();

 complex operator+ (const complex& c);
 complex operator- (const complex& c);
 complex operator* (const complex& c);
 complex operator/ (const complex& c);


 friend ostream& operator<< (ostream& os, const complex& c);
 friend istream& operator>> (istream& is, complex& c);


private:
 double real;
 double image;
};


#include "Complex.h"

int main()
{
 complex a, b, c;

 cout << "첫번째 복소수 입력 : ";
 cin >> a;

 cout << "두번째 복소수 입력 : ";
 cin >> b;

 cout << "a = " << a << endl;
 cout << "b = " << b << endl;

 cout << "a + b = " << a + b << endl;
 cout << "a - b = " << a - b << endl;
 cout << "a * b = " << a * b << endl;
 cout << "a / b = " << a / b << endl;

 return 0;
}



// Complex.h


complex complex::operator+ (const complex& c)
{

 return complex(real + c.real, image + c.image);
}
complex complex::operator-(const complex& c)
{
 return complex(real - c.real, image - c.image);
}

complex complex::operator*(const complex& c)
{
 return complex(real * c.real + image *c.image,
real * c.image + image *c.real);
    
}

complex complex::operator/(const complex& c)
{
 

 return complex((real * c.real + image * c.image)/(c.real * c.real + c.image * c.image),
                         (image * c.real - real* c.image)/(c.real * c.real + c.image * c.image));
}

ostream& operator<<(ostream& os, const complex& c)
{
 os <<c.real<<"+"<<"J"<<c.image<<")";
 return os;
}

istream& operator>>(istream& is, complex& c)
{
 is >> c.real;
 is >> c.image;;
 return is;
}



1>------ 빌드 시작: 프로젝트: 과제 제출, 구성: Debug Win32 ------
1>링크하고 있습니다...
1>Complex.obj : error LNK2019: "public: __thiscall complex::complex(double,double)" (??0complex@@QAE@NN@Z) 외부 기호(참조 위치: "public: class complex __thiscall complex::operator+(class complex const &)" (??Hcomplex@@QAE?AV0@ABV0@@Z) 함수)에서 확인하지 못했습니다.
1>Complex.obj : error LNK2019: "public: __thiscall complex::~complex(void)" (??1complex@@QAE@XZ) 외부 기호(참조 위치: _main 함수)에서 확인하지 못했습니다.
1>C:\Users\computer\Documents\Visual Studio 2008\Projects\과제 제출\Debug\과제 제출.exe : fatal error LNK1120: 2개의 확인할 수 없는 외부 참조입니다.
1>빌드 로그가 "file://c:\Users\computer\Documents\Visual Studio 2008\Projects\과제 제출\과제 제출\Debug\BuildLog.htm"에 저장되었습니다.
1>과제 제출 - 오류: 3개, 경고: 0개
========== 빌드: 성공 0, 실패 1, 최신 0, 생략 0 ==========


디버깅을 하면 이렇게 오류가 나네요

~Complex 를 지우면 오류가 하나 줄어들긴한데 firend로 +=,-= 도 추가해줘야되서 함부로 손대기가 어렵네요 ...

전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호