Re: [語法] int sum(0)
※ 引述《MoseHas (非主流摩斯) (′‧ω‧‵)》之銘言:
: 比如constructor
: class anything
: {
: public:
: anything();//default
: anything(int a,int b);//constructor
: private:
: int x;
: int y;
: }
: int main()
: {
: anything something(10,20);
: ...
: }
: 如果用 「 = 」 是沒辦法做initialization的
: 如有講錯的部分請強者補完,感謝~
硬要用 = 來做初始化的話,可以用:
anything something = anything(10,20);
在初始化時這樣做,不會造成多一次 copy constructor (temp object copying)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.126.1.195
推
06/12 14:29, , 1F
06/12 14:29, 1F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章