mbsim-env / fmatvec

A fast vector/matrix library
https://www.mbsim-env.de
GNU Lesser General Public License v2.1
10 stars 5 forks source link

Fix msvc operator search #12

Closed GreenGary closed 4 years ago

GreenGary commented 4 years ago

MSVC does not consider the operators from linear_algebra_complex.h if they are declared after usage, e.g. in Vector operator*(&x, &alpha) {} The fix in testast.cc solves compile issues, but the responsibility to include in correct order remains at the library user. A permanent fix would be to add #include "fmatvec/linear_algebra_complex.h" to linear_algebra.h . I preferred the other solution, because I cannot decide, if this is a desired dependency between these two headers. Or if e.g. a third public header would be better, that includes all internal headers in the correct order.

BTW: The error message is pointing into the wrong direction...

fmatvec\linear_algebra.h(927): error C2678: binary '*': no operator found which takes a left-hand operand of type 'const AT' (or there is no acceptable conversion)
        with
        [
            AT=std::complex<double>
        ]
fmatvec\ast.h(139): note: could be 'fmatvec::SymbolicExpression fmatvec::operator *(int,const fmatvec::SymbolicExpression &)'
fmatvec\ast.h(135): note: or       'fmatvec::SymbolicExpression fmatvec::operator *(double,const fmatvec::SymbolicExpression &)'
fmatvec\linear_algebra.h(927): note: while trying to match the argument list '(const AT, const AT2)'
        with
        [
            AT=std::complex<double>
        ]
        and
        [
            AT2=int
        ]
fmatvec\check\testast.cc(33): note: see reference to function template instantiation 'fmatvec::Vector<fmatvec::Var,AT> fmatvec::operator *<fmatvec::Var,AT,int>(const fmatvec::Vector<fmatvec::Var,AT> &,const AT2 &)' being compiled
friedrichatgc commented 4 years ago

I think adding template function declarations for complex types to linear_algebra.h is the proper way. I have added a commit with this change but cannot check if this compiles with MSVC. Please check if it compiles just merge this PR if it does not compile I'm happy to merge our proposal (without my commit on top of it)