- void Date::operator=(const Date& dt)
- {
- if (this != &dt)
- {
- mo = dt.mo;
- da = dt.da;
- yr = dt.yr;
- delete [] month;
- if (dt.month != NULL)
- {
- month = new char [std::strlen(dt.month)+1];
- std::strcpy(month, dt.month);
- }
- else
- month = NULL;
-
- }
- }
一些看到的c++面試題 自己試着回答一下
1、T是一個class,T a=b;和 T a; a=b; 有什麼不同?
前者: 調用複製構造函數。
後者: 調用 重載的賦值操作符函數
2、重載T的賦值操作符時參數和返回值分別是什麼?
3、class T1有一個char成員變量,class T2有一個char成員變量還有個void f();成員函數,在4字節對齊的情況下,sizeof(T1)和sizeof(T2)分別是多少?
4 4
4、class T
{
public:
void f1(){...}
void f2()const{...}
};
問f1和f2的區別?
f1()可以修改成員變量。
f2()不可以修改成員變量。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.