微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

错误C2338:YOU_MIXED_DIFFERENT_NUMERIC_TYPES

如何解决错误C2338:YOU_MIXED_DIFFERENT_NUMERIC_TYPES

我在Eigen库的eigen / src / Core / AssignEvaluator.h(834)行收到此错误

错误C2338:YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLYLY

基于编译器日志,我认为错误是由代码中的以下行触发的:

class IndexedMesh {
    
    const TriangleMesh* m_tm;

    // ...
}

Vec3d IndexedMesh::normal_by_face_id(int face_id) const {
    return m_tm->normal_by_face_id(face_id); // => Error is thrown here
}

Vec3f TriangleMesh::normal_by_face_id(int face_id) const
{
    return Vec3f();
}

完整的编译器日志是这个:

c:\users\m3\repos\qt3d-editor\editorlib\deps\eigen\eigen\src/Core/AssignEvaluator.h(834): error C2338: YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY
c:\users\m3\repos\qt3d-editor\editorlib\deps\eigen\eigen\src/Core/PlainObjectBase.h(732): note: see reference to function template instantiation 'void Eigen::internal::call_assignment_no_alias<Derived,Eigen::Matrix<float,3,1,2,1>,Eigen::internal::assign_op<double,float>>(Dst &,const Src &,const Func &)' being compiled
        with
        [
            Derived=Eigen::Matrix<double,Dst=Eigen::Matrix<double,Src=Eigen::Matrix<float,Func=Eigen::internal::assign_op<double,float>
        ]
c:\users\m3\repos\qt3d-editor\editorlib\deps\eigen\eigen\src/Core/PlainObjectBase.h(537): note: see reference to function template instantiation 'Derived &Eigen::PlainObjectBase<Derived>::_set_noalias<Eigen::Matrix<float,1>>(const Eigen::DenseBase<Eigen::Matrix<float,1>> &)' being compiled
        with
        [
            Derived=Eigen::Matrix<double,1>
        ]
c:\users\m3\repos\qt3d-editor\editorlib\deps\eigen\eigen\src/Core/PlainObjectBase.h(537): note: see reference to function template instantiation 'Derived &Eigen::PlainObjectBase<Derived>::_set_noalias<Eigen::Matrix<float,1>
        ]
c:\users\m3\repos\qt3d-editor\editorlib\deps\eigen\eigen\src/Core/Matrix.h(378): note: see reference to function template instantiation 'Eigen::PlainObjectBase<Eigen::Matrix<double,1>>::PlainObjectBase<Derived>(const Eigen::DenseBase<Derived> &)' being compiled
        with
        [
            Derived=Eigen::Matrix<float,1>
        ]
c:\users\m3\repos\qt3d-editor\editorlib\deps\eigen\eigen\src/Core/Matrix.h(377): note: see reference to function template instantiation 'Eigen::PlainObjectBase<Eigen::Matrix<double,1>
        ]
..\..\qt3d-editor\editorlib\src\libslic3r\SLA\IndexedMesh.cpp(119): note: see reference to function template instantiation 'Eigen::Matrix<double,1>::Matrix<Derived>(const Eigen::EigenBase<Derived> &)' being compiled
        with
        [
            Derived=Eigen::Matrix<float,1>
        ]

解决方法

Vec3dVec3f之间的类型不匹配是导致错误的原因。

// Caller of the method:
Vec3d IndexedMesh::normal_by_face_id(int face_id) const {
    return m_tm->normal_by_face_id(face_id);
}

// Bad method:
Vec3f TriangleMesh::normal_by_face_id(int face_id) const
{
    return Vec3f();
}

// Fine method:
Vec3d TriangleMesh::normal_by_face_id(int face_id) const
{
    return Vec3d();
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。