代码之家  ›  专栏  ›  技术社区  ›  Igor

pimpl STL和DLL

  •  0
  • Igor  · 技术社区  · 9 年前
    class __declspec(dllexport) Foo
    {
    private:
        struct Impl;
        Impl *pimpl;
    public:
        Foo();
        virtual ~Foo();
        Impl &GetVector();
    };
    
    Foo::Impl
    {
    std::vector<Bar> m_vec;
    }
    
    Foo::Foo() : pimpl( new Impl )
    {
    }
    
    Foo::~Foo()
    {
        delete pimpl;
    }
    
    Impl &Foo::GetVector()
    {
        return *pimpl;
    }
    

    MSVC 2010出现编译错误:

    缺少“;”在“&”之前

    有没有简单的方法来解决这个问题?

    非常感谢。

    1 回复  |  直到 9 年前
        1
  •  0
  •   JubileeTheBear    9 年前

    检查您的退货类型 Foo::GetVector 作用你的 Impl 结构包含在 Foo 类,所以为了访问它,您必须编写 Foo::Impl .