[go: up one dir, main page]

VC++ 2015 compiler error: deleted copy assignment operator for Block (and base classes)

Submitted by Michael Hofmann

Assigned to Nobody

Link to original bugzilla bug (#920)
Version: 3.3 (current stable)
Operating system: Windows

Description

I am failing to compile the following simple program using VC++ 2015 Preview and Eigen changeset 7dad5f79 (tip, as of writing):


#include <Eigen/Core>

int main()
{
Eigen::Matrix3f m = Eigen::Matrix3f::Zero();
Eigen::Matrix3f n = Eigen::Matrix3f::Zero();
m.block<2, 2>(0, 0) = n.block<2, 2>(0, 0);
}

The compiler complains that the copy assignment operator of Block<> is deleted:

1>test.cpp(66): error C2280: 'Eigen::Block<Derived,2,2,false> &Eigen::Block<Derived,2,2,false>::operator =(const Eigen::Block<Derived,2,2,false> &)': attempting to reference a deleted function
1> with
1> [
1> Derived=Eigen::Matrix<float,3,3,0,3,3>
1> ]
1> eigen\eigen\src\core\block.h(148): note: compiler has generated 'Eigen::Block<Derived,2,2,false>::operator =' here
1> with
1> [
1> Derived=Eigen::Matrix<float,3,3,0,3,3>
1> ]

which might or might not be a valid complaint, since the class contains non-static const variables.
See also http://en.cppreference.com/w/cpp/language/as_operator#Deleted_implicitly-declared_copy_assignment_operator.

I have tried adding an explicit definition for the copy assignment operator by calling the respective operator of its base class and returning *this, but this operation becomes viral. The compiler appears to require explicit copy assignment operator definitions for all base classes. (And I don't really want to patch this myself for our code base, because I'd probably get it wrong...)

What is the best solution here - just adding explicit definitions for all copy assignment operators up the inheritance hierarchy? Or something else?

Edited by Antonio Sánchez