Here's the minimum code:
#include <iostream>
#include <complex>
using namespace std;
class Test {
static const double dt = 0.1;
public:
void func();
};
void Test::func() {
cout << dt << endl; // OK!
cout << dt*complex<double>(1.0, 1.0) << endl; // Undefined reference
}
int main() {
Test a;
a.func();
}
The noted line gives a undefined reference to `Test::dt'. I could make a temporary variable every time I want to multiply a complex number with dt, but that is inconvenient as I am multiply many static const members with complex numbers in my code.
My guess is that when multiplying dt with a complex number, it needs, for some reason, the address of dt (i.e. &dt, which seems weird.
Any ideas why this error happens and how to make it work more elegantly than doing a double temp = dt; before every time I want to multiply it with a complex number?