c++中的单态模式。(就是不知道为什么用typedef)

xiaoxiao2021-02-28  65

// Array.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <stdio.h> #include <iostream.h> class A{ typedef A* PA; private: static const PA pa; A(){} public: static const PA GetA(){ return pa; } void hello() const { cout<<"Hello!"<<endl; } }; const A::PA A::pa=new A(); //const static A pa; int main(int argc, char* argv[]) { A* pa=A::GetA(); pa->hello(); }

 

转载请注明原文地址: https://www.6miu.com/read-73491.html

最新回复(0)