C++ 单例模式中处理在类中声明一个指向一个自己的指针,在编译时显示定义的指针未定义的处理办法

来源:互联网 发布:坂本龙马地位 知乎 编辑:程序博客网 时间:2024/06/06 12:57

参考博客:http://bbs.csdn.net/topics/10439749

#include<iostream>#include "test.h"using namespace std;int main(){    test *p = test::createtest();return 1;}

#pragma onceclass test{public:test(void);~test(void);static test *test_t;static test* createtest();};

#include "test.h"test* test::test_t;test::test(void){}test::~test(void){} test*  test::createtest() {        test_t = new test();    return 0; }
在类的定义文件的头部:必须加上LCD* LCD::lcd;

参考代码:http://download.csdn.net/detail/u010261063/9503302

0 0
原创粉丝点击