C++初始化普通成员的特点来调用静态初始化函数。当然,这需要定义一个额外的静态成员变量来辅助一下。 [cpp] view plain copy print ? #include <iostream> #include <string> #include <vector> class Test1 { public: Test1() { std::cout << "Test1 constructor..." << std::endl; }; virtual ~Test1() { std::cout << "Test1 deconstructor..." << std::endl; }; }; class Test2 { public: static std::vector<std::string> stringList; private: static bool __init; static bool init() { stringList.push_back("string1..."); stringList.push_back("string2..."); stringList.push_back("string3..."); return true; } }; Test1 test1; std::vector<std::string> Test2::stringList; bool Test2::__init = Test2::init(); int main() { std::cout << Test2::stringList.size() << std::endl; return EXIT_SUCCESS; }