2014.5.27 reference: C++ primer 5th, $7.6:Static Class Members TOPIC 1:一个类中的member(data member和function member)可以声明为static,需要申明为static的情况有一下原因: 1:使用的客观需要:需要某个member是associated with the class,not with individual objects(如银行class中的prime interest rate这个
Misunderstanding of static member class : For most programmers, comparing to SMC ,we may be more familiar with static field . so we may analogously guess how SMC works according to static field's feature. That leads to a misunderstanding.--SMC may on
Recently, I've started to review and learn C++ techniques. During the learning process, I followed a learn-by-example methodology, which I consider to be very effective. From now on, I'll use this blog to explain key points and interesting topics in
Extraction from C++ primer 5th Edition 7.1.2 The purpose of the const that follows the parameter list of an ordinary member function is to modify the type of the implicit this pointer. By default, the type of this is a const pointer to the nonconst v
一个常量成员函数(const member function), 可以读取类的数据成员,但不能修改类的数据成员. 1 声明 在成员函数声明的参数列表后,加上 const 关键字,将其声明为常量成员函数(const member function),表明其不被允许修改类的数据成员 下面定义了一个 Date 类,分别以年.月.日的形式来表示日期 class Date { public: int day() const { return d; } int month() const { return
单例模式的static方法和非static方法是否是线程安全的? 答案是:单例模式的static方法和非static方法是否是线程安全的,与单例模式无关.也就说,如果static方法或者非static方法不是线程安全的,那么不会因为这个类使用了单例模式,而变的安全. 闲话休说,看代码: import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class TestSingl