C++ std::共享ptr&;boost::共享的ptr差异

C++ std::共享ptr&;boost::共享的ptr差异,c++,boost,c++11,shared-ptr,C++,Boost,C++11,Shared Ptr,我有以下代码: // 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_

我有以下代码:

// 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();
}
//interface.h
#ifndef接口
#定义接口
#包括
第三类接口{
公众:
虚拟界面()=0;
虚空doSomething()=0;
};
内联接口::~IInterface(){}
typedef std::shared_ptrIIntPtr;
IIntPtr makeInterface();
#endif//接口
//impl.cpp
#包括“interface.h”
类接口:公共接口{public:
接口(){}
~Interface(){}
void doSomething(){};
IIntPtr makeInterface(){返回IIntPtr(新接口());}
//main.cpp
#包括“interface.h”
使用名称空间std;
int main()
{
auto p=makeInterface();
p->doSomething();
}
现在:如果我使用
typedef std::shared_ptrIIntPtr一切正常,但如果我使用
typedef boost::shared_ptrIIntPtr我有一些编译器错误:

  • 编译器错误C2027:在定义类型之前,无法使用该类型。要解决此错误,请确保在引用该类型之前已完全定义该类型。
  • 编译器错误C2079:“标识符”使用未定义的类/结构/联合“名称”
  • 编译器错误C2440:编译器无法从“type1”强制转换为“type2”

我使用的是msvc10,但代码必须使用msvc9.0编译,因此我必须使用Boos.SmartPtr


我错过什么了吗

OP在评论中回答了他自己的问题:他在尝试Boost版本时忘记了
#包括

当您切换到使用Boost时,是否也包括相应的标题?是否包括Boost标题,
“Boost/shared\u ptr.hpp”
?标准标题<代码> <代码>只定义了标准<代码> STD::SyrdYPPTR < /C++ >:是的:当我使用Boost和C++时包含11@elvis:它需要是“boost/shared\ptr.hpp”而不是作用域\u ptrok。。。我还包括。我没有问题了。哎呀。。。我太傻了。。。我为这件蠢事浪费了很多时间