我需要在 C++ 中访问复杂数据 vector 的特定元素。
这是我的:
vector< complex<float> > x; // Create vector of complex numbers
x.push_back(complex<float>(1, 2)); // Place 1 + j2 in vector
x.push_back(complex<float>(2, 1)); // Place 2 + j1 in vector
// Attempt at accessing the zero-th elements real part
float temp1 = x.at(0).real;
float temp2 = x[0].real;
这会在 Visual Studio 2015 中产生以下错误:
Severity Code Description Project File Line Suppression State Error C3867 'std::_Complex_base::real': non - standard syntax; use '&' to create a pointer to member opencv_dft c : \users\josh\VS_project\main.cpp 101
最佳答案
您忘记了调用 real()
时的括号。你需要:
float temp1 = x.at(0).real();
float temp2 = x[0].real();
real()
是成员函数,不是数据成员。
关于c++ - 使用复 vector 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45874751/