This topic has been archived. It cannot be replied.
-
工作学习 / 学科技术讨论 / 讨论一下: 写c++的类时,有人喜欢声明指针成员变量,有人喜欢直接用成员变量实体。各有什么优点?
-smile2007(smile2007);
2007-11-21
(#4071528@0)
-
sorry, 什么叫 指针成员变量?something like Object *my = new Object("hello world") 什么是 成员变量实体?是 Object my("hello world") 吗?不同需要的时候用不同啊,需要动态的时候用前者,不需要用后者(省工夫)
-sowen(sowen);
2007-11-21
(#4071672@0)
-
You can use forward declaration for the class when using 指针成员变量, which means you can put the header file for that class in .cpp file, it can avoid exposing details about that class and reduce compile time.
-liquid(avaya);
2007-11-21
(#4071753@0)
-
成员变量实体除了省功夫,还有别的优点吗? 对于大一点的软件,这会消耗大量的编译时间。
-smile2007(smile2007);
2007-11-21
(#4071804@0)
-
interesting, why do yo care about "大量的编译时间"?..you can have a cup of coffee or shop around when system is compiling....haha
-jj999ca(jj999ca);
2007-11-21
(#4072351@0)
-
Hehe.Firefighter likes coffee break when fighting fire.
-smile2007(smile2007);
2007-11-21
(#4072368@0)
-
指针对多态和物理设计的支持好。实例变量对生命周期的控制支持好。如果两种情况用反了,后患无穷,劳民伤财,被世人唾骂。
-ccloafer(梦游安大略);
2007-12-23
(#4140164@0)