[問題] 關於=的多載..
以下是程式碼
#include <iostream>
#include <cstdlib>
using namespace std;
class CWin
{
private:
char id,*title;
public:
CWin(char i='D',char *text="default window"):id(i)
{
title=new char[50];
strcpy(title,text);
}
void set_data(char i,char *text)
{
id=i;
strcpy(title,text);
}
void show(void)
{
cout << "window" << id << ": " << title << endl;
}
~CWin(){delete[] title;}
CWin(const CWin &win)
{
id=win.id;
strcpy(title,win.title);
}
char get_id()
{
return this->id;
}
char get_title()
{
return this->title;
}
};
void operator=(CWin &w1,CWin &w2)
{
w1.get_id()=w2.get_id();
strcpy(w1.get_title(),w2.get_title());
return;
}
int main(void)
{
CWin win1('A',"main window");
CWin win2;
win1.show();
win2.show();
operator=(win1,win2);
win1.show();
system("pause");
return 0;
}
在這個程式碼裡,我嘗試著想要把operator=當成一般函式來寫~
但是卻無法編譯過,我想了很久不知道錯在哪邊
麻煩各位大大可以幫我看一下~謝謝!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.44.146.169
推
02/26 22:28, , 1F
02/26 22:28, 1F
→
02/26 22:29, , 2F
02/26 22:29, 2F
→
02/26 22:29, , 3F
02/26 22:29, 3F
→
02/26 22:30, , 4F
02/26 22:30, 4F
→
02/26 22:30, , 5F
02/26 22:30, 5F
→
02/26 22:36, , 6F
02/26 22:36, 6F
推
02/26 22:52, , 7F
02/26 22:52, 7F
→
02/26 22:53, , 8F
02/26 22:53, 8F
→
02/26 23:33, , 9F
02/26 23:33, 9F
推
02/28 02:03, , 10F
02/28 02:03, 10F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章
74
180