在 - C++入門,第三版斯坦利 B.利普曼,喬西·拉喬這個析構函數聲明是C++ Primer(Stanley Lippman)中的一個錯字嗎?
它說的:
15.1運算符重載
正如我們在前面章節的例子中所看到的,運算符重載允許程序員爲類類型的操作數定義預定義運算符的版本(如第4章所述)。例如,第3.15節中介紹的String類定義了許多重載操作符。這裏是我們的String類的定義:
#include <iostream>
class String;
istream& operator>>(istream &, String &);
ostream& operator<<(ostream &, const String &);
class String {
public:
/overloaded set of constructors
// provide automatic initialization
String(const char * = 0);
String(const String &);
// destructor: automatic deinitialization **------> NOTE**
String(); //**------> NOTE**
// overloaded set of assignment operators
String& operator=(const String &);
String& operator=(const char *);
// overloaded subscript operator
char& operator[](int) const;
// overloaded set of equality operators
// str1 == str2;
bool operator==(const char *) const;
bool operator==(const String &) const;
// member access functions
int size() { return _size; }
char* c_str() { return _string; }
private:
int _size;
char *_string;
};
如何String()
是析構函數?是不是析構函數應該出現一個波浪號前綴,就像這樣~String()
?
猜,我發現SO
只是看起來像一個錯字。 – jmccarthy 2011-03-28 01:46:20
@Downvoter :: downvote的任何愚蠢的原因?對於由SO引用的書中學習C++的人來說,這是一個有效的問題。 – Sadique 2011-03-28 02:01:11