C++使用定义静态类,禁止实例化&&继承程序示例(借助纯虚函数是的只能以类名访问属性和方法)
#include <iostream> using namespace std; class TestStatic final { public: static void PrintName() { cout << "Myname is test Statci class...." << endl; } protected: virtual void DummyFunc() = 0; }; //class TT2 :TestStatic //error //{ // // //}; //测试 int main() { TestStatic::PrintName(); //TestStatic::DummyFunc(); //error }