正如标题所提到的,我的问题很明显,我详细描述了这个场景.在文件singleton.h中有一个名为singleton的类,由singleton模式实现,如下所示:
/*
* singleton.h
*
* Created on: 2011-12-24
* Author: bourneli
*/
#ifndef SINGLETON_H_
#define SINGLETON_H_
class singleton
{
private:
singleton() {num = -1;}
static singleton* pInstance;
public:
static singleton& instance()
{
if (NULL == pInstance)
{
pInstance = new singleton();
}
return *pInstance;
}
public:
int num;
};
singleton* singleton::pInstance = NULL;
#endif /* SINGLETON_H_ */
Run Code Online (Sandbox Code Playgroud)
然后,有一个名为hello.cpp的插件如下:
#include <iostream>
#include "singleton.h"
extern "C" void hello() {
std::cout << "singleton.num in hello.so : " << singleton::instance().num << std::endl;
++singleton::instance().num; …Run Code Online (Sandbox Code Playgroud)