c++ 대입연산자 관련
글쓴이: iiijj111 / 작성시간: 금, 2015/11/27 - 11:41오후
자꾸 왼쪽 객체에 수정할수 있는 lvalue여야 합니다 라고 하면서
컴파일 에러나는대 뭐가문제일까요 ㅠㅠ
대입연산자 정의
CBankAccount& CBankAccount::operator = (const CBankAccount & account1)
{
SetBankName (account1.m_BankName);
m_Cash = account1.m_Cash;
m_Interest = account1.m_Interest;
delete [] m_HistoryCash;
m_HistoryCash = new int[12];
int temp;
for(int i = 0; i < 12; i++)
{
temp = account1.m_HistoryCash[i];
m_HistoryCash[i] = temp;
}
return *this;
}Forums:


참고해보세요.
일찍 자야 건강합니다.
#include <iostream> #include <string.h> class CBankAccount { public: CBankAccount(){}; ~CBankAccount(){}; void SetBankName(const char * buf) { strcpy(m_BankName, buf); } char m_BankName[100]; int m_Cash; int m_Interest; int * m_HistoryCash; CBankAccount& operator = ( CBankAccount & account1) { SetBankName (account1.m_BankName); m_Cash = account1.m_Cash; m_Interest = account1.m_Interest; if(m_HistoryCash != NULL) { delete [] m_HistoryCash; } m_HistoryCash = new int[12]; int temp; for(int i = 0; i < 12; i++) { temp = account1.m_HistoryCash[i]; m_HistoryCash[i] = temp; } account1.m_Cash = 100; return *this; } }; class A { public: A(){}; ~A(){}; int a; }; int main(int argc, char** argv) { CBankAccount b1; CBankAccount b2; strcpy(b2.m_BankName, "BankName"); b2.m_Cash = 10; b2.m_HistoryCash = new int[12]; b2.m_Interest = 30; printf("b2.m_Cash %d\n", b2.m_Cash); b1 = b2; printf("b1.m_Cash %d\n", b1.m_Cash); printf("b2.m_Cash %d\n", b2.m_Cash); delete [] b2.m_HistoryCash; // A a; A b; a = b; return 0; }----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.
매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.
각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com
댓글 달기