作者sorryChen (陈扬和)
看板Programming
标题Re: 请问C++ Class中 const static object 的life …
时间Fri Sep 19 16:12:33 2008
感谢回覆 但是我这样会有link error 耶
不过我的class 不是string 而是另一个自己定义的class, 就叫他C2吧
而且我把 static const C::C2 foo("hello");是写在 C.cpp档中的..
不是写在C.h档中的, 可是改成指标就可以编译成功,不知道哪里会有错
※ 引述《tinlans ( )》之铭言:
: ※ 引述《sorryChen (陈扬和)》之铭言:
: : 标题: Re: 请问C++ Class中 const static object 的life …
: : 时间: Fri Sep 19 02:49:14 2008
: : 感谢大师的指点, memory leak就是我要问的
: : 所以其实不应该用指标 不然就得自己在main 结束前把它delete 掉
: : 是这样吧
: : 非常感谢
: : → sorryChen:可是不用指标好像没办法initialization 128.125.87.33 09/19 03:41
: 我一开始看的时候就很好奇,
: 为什麽你不这样写?
: class C {
: static const string foo;
: };
: static const string foo("hello");
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 128.125.87.33
1F:推 sunneo:cpp里面不用static 61.227.229.40 09/19 18:35
2F:→ sunneo:就只要const string C::C2 foo("hello"); 61.227.229.40 09/19 18:35
3F:推 machumer:如果要写在class 的definition 中那就只 221.169.119.10 09/30 23:10
4F:→ machumer:能是型别为int或是char 221.169.119.10 09/30 23:10
5F:→ machumer:其余型别就必须在source档中定义 221.169.119.10 09/30 23:11
6F:→ machumer:至於为什麽自己写的类别会出错,我猜应该 221.169.119.10 09/30 23:12
7F:→ machumer:是你自己写的类别的建构子的关系 221.169.119.10 09/30 23:13