C++ VS 2015更新3已删除副本分配运算符的错误

C++ VS 2015更新3已删除副本分配运算符的错误,c++,c++11,visual-studio-2015,C++,C++11,Visual Studio 2015,下面的代码在clang-3.8和GCC4.9.3上编译得很好 #include <vector> #include <algorithm> #include <iterator> class foo { }; class MyVec { public: MyVec() {} }; class MyInsert : public std::iterator<std::output_iterator_tag, void, vo

下面的代码在clang-3.8和GCC4.9.3上编译得很好

#include <vector>
#include <algorithm>
#include <iterator>

class foo 
{
};

class MyVec {
    public:
    MyVec() {}
};

class MyInsert :
    public std::iterator<std::output_iterator_tag, void, void, void, void>
{
  protected :
    MyVec &fV;

  public :
    explicit MyInsert (MyVec &v) : fV(v) {}

    MyInsert & operator= (void *value)
    {
        return *this;
    }

    MyInsert & operator* ()    { return *this; }
    MyInsert & operator++ ()   { return *this; }
    MyInsert & operator++(int) { return *this; }

};    

class test
{
    public:    
    void method()
    {
        MyVec retv;

        std::vector<const foo*> foovec;
        std::transform(foovec.begin(), foovec.end(),MyInsert(retv),[](const foo*)->void* { return nullptr;});
    }
};

int main(){
    return 0;
}
#包括
#包括
#包括
福班
{
};
类MyVec{
公众:
MyVec(){}
};
类别MyInsert:
公共标准:迭代器
{
受保护的:
MyVec&fV;
公众:
显式MyInsert(MyVec&v):fV(v){}
MyInsert&运算符=(无效*值)
{
归还*这个;
}
MyInsert&运算符*(){return*this;}
MyInsert&operator++(){return*this;}
MyInsert&operator++(int){return*this;}
};    
课堂测试
{
公众:
void方法()
{
MyVec-retv;
std::vector foovec;
std::transform(foovec.begin()、foovec.end()、MyInsert(retv),[](const foo*)->void*{return nullptr;});
}
};
int main(){
返回0;
}
然而,当在VS 2015 Update 3上编译时,它失败并显示以下错误消息

c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(458): error C2280: 'MyInsert &MyInsert::operator =(const MyInsert &)': attempting to reference a deleted function
test\mytests\main.cpp(33): note: compiler has generated 'MyInsert::operator =' here
c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(926): note: see reference to function template instantiation '_Iter &std::_Rechecked<_OutIt,_OutIt>(_Iter &,_UIter)' being compiled
        with
        [
            _Iter=MyInsert,
            _OutIt=MyInsert,
            _UIter=MyInsert
        ]
c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(950): note: see reference to function template instantiation '_OutIt std::_Transform_no_deprecate1<const foo**,_OutIt,_Fn1>(_InIt,_InIt,
_OutIt,_Fn1 &,std::input_iterator_tag,std::_Any_tag)' being compiled
        with
        [
            _OutIt=MyInsert,
            _Fn1=test::method::<lambda_45e8626339fc29aadca2bf2dd3420511>,
            _InIt=const foo **
        ]
c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(960): note: see reference to function template instantiation '_OutIt std::_Transform_no_deprecate<_InIt,_OutIt,_Fn1>(_InIt,_InIt,_OutIt,
_Fn1 &)' being compiled
        with
        [
            _OutIt=MyInsert,
            _InIt=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<const foo *>>>,
            _Fn1=test::method::<lambda_45e8626339fc29aadca2bf2dd3420511>
        ]
test\mytests\main.cpp(45): note: see reference to function template instantiation '_OutIt std::transform<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<const
foo *>>>,MyInsert,test::method::<lambda_45e8626339fc29aadca2bf2dd3420511>>(_InIt,_InIt,_OutIt,_Fn1)' being compiled
        with
        [
            _OutIt=MyInsert,
            _InIt=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<const foo *>>>,
            _Fn1=test::method::<lambda_45e8626339fc29aadca2bf2dd3420511>
        ]
        ]
c:\ProgramFiles(x86)\microsoft visual studio 14.0\vc\include\xutility(458):错误C2280:'MyInsert&MyInsert::operator=(const MyInsert&'):试图引用已删除的函数
test\mytests\main.cpp(33):注意:编译器已在此处生成“MyInsert::operator=”
c:\program files(x86)\microsoft visual studio 14.0\vc\include\algorithm(926):注意:请参阅正在编译的函数模板实例化“\u Iter&std::\u重新检查(\u Iter&,\u UIter)”的参考
具有
[
_Iter=MyInsert,
_OutIt=MyInsert,
_UIter=MyInsert
]
c:\program files(x86)\microsoft visual studio 14.0\vc\include\algorithm(950):注意:请参阅函数模板实例化“\u OutIt std::\u Transform\u no\u deprecate1(\u InIt,\u InIt,
_OutIt,_Fn1&,std::input_iterator_tag,std::_Any_tag)'正在编译
具有
[
_OutIt=MyInsert,
_Fn1=测试::方法::,
_InIt=常量foo**
]
c:\program files(x86)\microsoft visual studio 14.0\vc\include\algorithm(960):注意:请参阅函数模板实例化“\u OutIt std::\u Transform\u no\u deprecate(\u InIt,\u InIt,\u OutIt,
_正在编译Fn1&)
具有
[
_OutIt=MyInsert,
_InIt=std::_向量_迭代器,
_Fn1=测试::方法::
]
test\mytests\main.cpp(45):注意:请参阅正在编译的函数模板实例化“\u OutIt std::transform(\u InIt,\u InIt,\u OutIt,\u Fn1)”
具有
[
_OutIt=MyInsert,
_InIt=std::_向量_迭代器,
_Fn1=测试::方法::
]
]
我无法理解为什么它(VS编译器)无法找到复制赋值运算符,该运算符接受
void*
并在明确提供时返回
MyInsert&

深入了解(通过跟踪错误消息)

c:\ProgramFiles(x86)\microsoft visual Studio 14.0\vc\include\xutility

c:\ProgramFiles(x86)\microsoft visual Studio 14.0\vc\include\algorithm

还使我意识到调用
std::transformation
算法的实际函数调用了显式提供的拷贝分配,之后它进入
\u重新检查的
函数并进入
xutility

在该函数中,调用了复制分配运算符,该运算符预期(输入为
MyInsert&
,输出为
MyInsert&
),由于找不到,因此将错误消息显示为
尝试引用…

这个分析正确吗?如果没有,那么为什么不能编译在其他主要编译器上编译的代码呢?也许是虫子

附言

我目前使用的解决方法是删除
MyInsert
类中具有非引用成员的引用成员

我无法理解为什么它(VS编译器)无法找到复制赋值运算符,该运算符接受
void*
并在明确提供时返回
MyInsert&

采用
void*
的赋值运算符不是复制赋值运算符

编译器确实尝试使用复制赋值运算符,这显然不是显式提供的。它也不是隐式提供的,因为存在引用成员

输出迭代器必须满足的要求必须满足的要求必须满足的要求必须满足的要求不足为奇地要求您拥有一个拷贝赋值操作符。这是
MyInsert
所缺少的

为什么不能编译在其他主要编译器上编译的代码

虽然输出迭代器必须满足要求,但标准库实现不需要检查是否满足要求

希望概念的正式规范将成为未来标准的一部分,以改进此类情况下的错误消息

也许是虫子

该错误是代码中缺少的复制分配运算符。在这方面,VS和其他编译器都符合标准

我正在使用的当前解决方法是删除MyInsert类中具有非引用成员的引用成员


通过删除引用成员,可以允许复制赋值运算符的隐式声明。这就是它起作用的原因。要在保持类型副本可分配的同时继续引用对象,请使用普通指针而不是引用。

@NathanOliver我不觉得奇怪。很容易想象
std::transform
的一个实现,它不需要复制并分配输出迭代器。调用
std::transform
可能是一个错误-例如:无法保证它会工作-但我认为标准不要求实现检查是否满足类型要求。是的,我意识到了这一点。我的问题是复制构造函数也应该被删除,所以