I get a compilation error in Visual Studio 2015 when I try to declare a class variable when these classes use the PIMPL template.
foo.h:
#pragma once
class Foo
{
public:
Foo(const std::wstring& str,
const std::vector<std::wstring>& items);
~Foo();
private:
struct Impl;
std::unique_ptr<Impl> pimpl;
};
foo.cpp:
#include "stdafx.h"
#include "Foo.h"
struct Foo::Impl
{
public:
Impl(const std::wstring& str,
const std::vector<std::wstring>& items);
std::wstring str_;
std::vector<std::wstring> items_;
};
Foo::Foo(const std::wstring& str,
const std::vector<std::wstring>& items)
: pimpl(std::make_unique<Impl>(str, items))
{
}
Foo::~Foo() = default;
Foo::Impl::Impl(const std::wstring& str,
const std::vector<std::wstring>& items)
: str_(str),
items_(items)
{
}
If I declare a type variable Foousing the traditional syntax, it compiles fine:
Foo f(L"Hello", std::vector<std::wstring>());
However, if I declare it using auto, I get a compilation error:
auto f2 = Foo { L"Goodbye", std::vector<std::wstring>() };
error C2280: 'Foo :: Foo (const Foo &)': attempt to reference a remote function
note: the compiler generated 'Foo :: Foo' here
, Foo , unique_ptr . , , , .
Visual Studio 2013. Visual Studio 2015, , , .
- , - ?