我有以下代码:
// 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();
}现在:如果我使用typedef std::shared_ptr< IInterface > IIntPtr;,一切都很好,但是如果我使用typedef boost::shared_ptr< IInterface > IIntPtr;,就会出现一些编译器错误:
我使用的是msvc10,但是代码必须用msvc9.0编译,所以我必须使用Boos.SmartPtr
我是不是遗漏了什么?
发布于 2014-12-30 22:42:26
OP在评论中回答了他自己的问题:在尝试Boost版本时,他忘了使用#include <boost/shared_ptr.hpp>。
https://stackoverflow.com/questions/16171510
复制相似问题