lballabio / QuantLib

The QuantLib C++ library
http://quantlib.org
Other
5.38k stars 1.79k forks source link

Putting f_A in laplaceinterpolation.hpp into non-anonymous namespace causes LNK2005 in MSVS #78

Closed bcamel closed 8 years ago

bcamel commented 8 years ago

Recent change (43e90db) put Disposable<Array> f_A(const SparseMatrix &g, const Array &x) into QuantLib::detail namespace. This causes LNK2005 (violation of one definition rule) on Microsoft Visual Studio (tested on VS2015).

My usage: In my project, I put some universal helper functions into a library util.lib and link this library to an executable together with QuantLib.

The error vanished when making the function static:

namespace QuantLib {

namespace detail {

static Disposable<Array> f_A(const SparseMatrix &g, const Array &x) {
    return prod(g, x);
};

} 
lballabio commented 8 years ago

Thanks for the heads-up. I've committed a fix. Let me know if it works now.

bcamel commented 8 years ago

Works fine, thank you!

By the way, why is the static modificator unfavorable to solve this issue?

lballabio commented 8 years ago

static was ok, too, but given the choice I preferred to hide f_A further and reduce the possibility of name clashes.

If we didn't have to support older compilers we'd use lambdas for this kind of things. One day, hopefully...