[英]std::shared_ptr & boost::shared_ptr difference
I've the following code: 我有以下代码:
// interface.h
#ifndef INTERFACE_H
#define INTERFACE_H
#include <memory>
class IInterface {
public:
virtual ~IInterface() = 0;
virtual void doSomething() = 0;
};
inline IInterface::~IInterface() {}
typedef std::shared_ptr< IInterface > IIntPtr;
IIntPtr makeInterface();
#endif // INTERFACE_H
// impl.cpp
#include "interface.h"
class Interface : public IInterface { public:
Interface() {}
~Interface() {}
void doSomething() {} };
IIntPtr makeInterface() { return IIntPtr( new Interface() ); }
// main.cpp
#include "interface.h"
using namespace std;
int main()
{
auto p = makeInterface();
p->doSomething();
}
Now: if i use typedef std::shared_ptr< IInterface > IIntPtr;
现在:如果我使用typedef std::shared_ptr< IInterface > IIntPtr;
all is fine, but if I use typedef boost::shared_ptr< IInterface > IIntPtr;
一切都很好,但是如果我使用typedef boost::shared_ptr< IInterface > IIntPtr;
I've some compiler error: 我有一些编译器错误:
I'm using msvc10, but the code must compile with msvc9.0 so I have to use Boos.SmartPtr 我正在使用msvc10,但是代码必须与msvc9.0一起编译,因此我必须使用Boos.SmartPtr
Am I missing something? 我想念什么吗?
OP在评论中回答了他自己的问题:在尝试Boost版本时,他忘记了#include <boost/shared_ptr.hpp>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.