#include <iostream>
#include <string>
using namespace std;
class Example3 {
string data;
public:
Example3 (const string& str) : data(str) {}
Example3 () {}
const string& content () const {return data;}
};
int main(int argc, char const *argv[])
{
Example3 foo;
Example3 bar ("Test");
cout << "bar's content: " << bar.content() << endl;
return 0;
}
C++默認構造器
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
【深入理解C++11 筆記】——1 保證穩定性和兼容性
Duco
2020-07-06 15:47:39
【c++基礎】虛函數的使用以及和成員函數的區別
Duco
2020-07-06 15:47:29
在C/C++項目中合理使用宏
Duco
2020-07-06 15:47:29
3rd_party/flatbuffers/tmp/flatc: No such file or directory
ShellCollector
2020-07-05 19:32:29
android-ndk-r15c libncurses.so.5
ShellCollector
2020-07-04 20:20:34
vector 動態刪除元素,釋放內存的研究
Bing_Lee
2020-07-02 16:13:54
對於c++中的i++與++i的分析
Bing_Lee
2020-07-02 16:13:54
動態鏈接庫(dll)與靜態連接庫(lib)
xiaofeilongyu
2020-07-01 00:34:01
5003.c++定義hpp文件
xhome516
2020-06-27 10:57:14
c++類中static、const、static const成員變量初始化
gg半夏时光
2020-06-25 22:56:31
/C++ 指針的指針:
zero2100
2020-06-24 22:37:36