diff --git a/include/effective_c++/Clock.h b/include/effective_c++/Clock.h index 58644f1..ec3fdfa 100644 --- a/include/effective_c++/Clock.h +++ b/include/effective_c++/Clock.h @@ -17,7 +17,10 @@ namespace effective { private: virtual std::string onTick() const; - int tick_frequency; + //> 成员变量初始化的顺序为:先声明时初始化,然后初始化列表初始化,最后构造函数初始化。 + //> 如果调用了一个类的默认构造函数,那么这个变量的值则来自于声明初始化。如果声明时 + //> 未初始化,则此变量值为该类型的默认值。 + int tick_frequency{1}; bool is_running{true}; }; } // namespace effective diff --git a/include/effective_c++/home/home.h b/include/effective_c++/home/home.h index 3a32ec8..9d7d22a 100644 --- a/include/effective_c++/home/home.h +++ b/include/effective_c++/home/home.h @@ -50,7 +50,10 @@ namespace effective { std::string boardcastAddress() const; protected: - std::string address_; + //> 成员变量初始化的顺序为:先声明时初始化,然后初始化列表初始化,最后构造函数初始化。 + //> 如果调用了一个类的默认构造函数,那么这个变量的值则来自于声明初始化。如果声明时 + //> 未初始化,则此变量值为该类型的默认值。 + std::string address_ = ""; private: //> doHealthValue是private级别,派生类访问不到,但是派生类可以重写属于自己的函数。 diff --git a/test/source/home_factory_test.cpp b/test/source/home_factory_test.cpp index 73d46c8..ea65322 100644 --- a/test/source/home_factory_test.cpp +++ b/test/source/home_factory_test.cpp @@ -12,4 +12,9 @@ TEST_CASE("HomeFactory") { CHECK(one_cave->GetAddress("decorate ") == "decorate ParaMountain"); CHECK(one_cave->GetAddress() == "ParaMountain"); CHECK(one_cave->boardcastAddress() == "This from home begin send address Tick begin My cave address is : ParaMountainMy cave address is : ParaMountainMy cave address is : ParaMountainend."); + auto one_nest = home_factory.makeHome("Nest"); + CHECK(one_nest->draw(2) == "let paint the house as Blue"); + CHECK(one_nest->healthValue() == "before check health of full Nest after."); + CHECK(one_nest->GetAddress("decorate ") == "decorate "); + CHECK(one_nest->boardcastAddress() == "This from home begin send address Tick begin My nest address is : My nest address is : My nest address is : end."); }