Registered Member
|
Hi all,
I was wondering if anyone has used Eigen with fixed size matrices and multiple inheritance as I am facing some errors due to the multiple definition of EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
error C2385: ambiguous access of 'delete' 2> could be the 'delete' in base 'Foo1' 2> or could be the 'delete' in base 'Foo2' 2> This diagnostic occurred in the compiler generated function 'void *Derived::__delDtor(unsigned int)' One solution I guess is to hide the fixed size matrices in a struct as per the documentation but it becomes a bit cumbersome for the derived classes and requires a heap allocation. However, do we really need to align in derived class ? Would a solution be to actually add EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(false) If not would there be any issues if we just redefine EIGEN_MAKE_ALIGNED_OPERATOR_NEW in the Derived classes so that we hide the inherited functions ? |
Moderator
|
yes, this is the right solution. |
Registered Member
|
Thank you for your answer.
Could you provide some explanation though ? I would have thought that since Derived does not have any fixed size matrices as members it would not need the EIGEN_MAKE_ALIGNED_OPERATOR_NEW. The base classes that have the fixed matrices also have the macro so that should take care of their initialization. |
Moderator
|
Since Derived inherits Foo1, any Derived instance has to be properly allocated to preserve the alignement requirement of Foo1. In the case of single inheritance, like:
class Derived: public Foo1 {}; it is not needed to redefine operator new in Derived because it is automatically inherited from Foo1. More precisely, doing new Derived; will call Foo1::operator new that will call Eigen's aligned memory allocator to allocate the entire Derived object, that is a buffer of size sizeof(Derived). Redefining operator new in Derived using Eigen's macro is therefore harmless. |
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]