我使用智能指针做全句变量,在文件"autoptr.h"中定义,
定义如下: auto_ptr<TServ> pServ;
然后在使用的文件中用 extern "C" auto_ptr<TServ> pServ,编译后出现如下错误:
tstandard.obj : error LNK2005: "class std::auto_ptr<class TServ> pServ" (?pServ@@3V?$auto_ptr@VTServ@@@std@@A) already defined in debug_main.obj但是如果我在定义 pServ的前面加 static 关键字,即
static auto_ptr<TServ> pServ; 就没问题,加static 的变量只能在包含的文件中使用,因为我有多个文件,是不能做全句变量的。
请问各位大侠,怎么解决???
定义如下: auto_ptr<TServ> pServ;
然后在使用的文件中用 extern "C" auto_ptr<TServ> pServ,编译后出现如下错误:
tstandard.obj : error LNK2005: "class std::auto_ptr<class TServ> pServ" (?pServ@@3V?$auto_ptr@VTServ@@@std@@A) already defined in debug_main.obj但是如果我在定义 pServ的前面加 static 关键字,即
static auto_ptr<TServ> pServ; 就没问题,加static 的变量只能在包含的文件中使用,因为我有多个文件,是不能做全句变量的。
请问各位大侠,怎么解决???
将解释为C++ symbol
extern "C" auto_ptr<TServ> pServ,
将其转换为了C symbol
改为 extern auto_ptr<TServ> pServ,
class YourClass
{
......
public:
static auto_ptr<TServ> pServ;
.......
}在引用他的时候如下
YourClass::auto_ptr<TServ> pServ;
即可希望对你有所帮助!