在 -std=c++11 上编译时C++ "no match for operator >>"
C++ "no match for operator >>" when comiling on -std=c++11
我有一个函数,可以将文件中的数据(数字)加载到复杂的表中。在-std=c++98上,一切都在编译,没有错误,但当我想用-std=c++11编译时,会出现带有运算符>>的问题。
template <typename T> void load(char name[], complex<T> table[], int len) {
ifstream dane;
dane.open(name);
for (int i = 0; i < 2 * len; i++)
(i % 2 == 0 ? dane >> table[i / 2].real() : dane >> table[(i - 1) / 2].imag());
dane.close();
}
no match for 'operator>>' in 'dane >> (table + ((sizetype)(((unsigned int)((i + -1) / 2)) * 16u)))->std::complex<double>::imag()'
no match for 'operator>>' in 'dane >> (table + ((sizetype)(((unsigned int)(i / 2)) * 16u)))->std::complex<double>::real()
在这种情况下,有许多无法将参数从双精度转换为双精度的数据。
那么,我能做些什么,用c++11标准运行它呢?
http://en.cppreference.com/w/cpp/numeric/complex/imag
这些都没有返回引用,因此该值不是左值,而是右值(我相信),并且你不能分配给右值(想象一下写dane >> 5;
,同样的处理。你必须读入临时变量,然后根据I,你将写入real
或imag
。
(书写示例:table[i /2].real(myTemporaryVariable);
)
编辑:
工作功能:
template <typename T> void load(char name[], complex<T> table[], int len) {
ifstream dane;
dane.open(name);
for (int i = 0; i < 2 * len; i++)
{
double read;
dane >> read;
if (!(i%2)) table[i / 2].real(read);
else table[(i - 1) / 2].imag(read);
}
dane.close();
}
此外,我不知道为什么它使用-std=c++99 编译
在C++11中,std::complex的real()和imag()成员变成了constexpr,这意味着const。因此,他们再也没有操作员>>了。看见http://en.cppreference.com/w/cpp/numeric/complex/imag用于规范。我看不出这个构造如何在C++11中工作。
相关文章:
- "error: no matching function for call to"构造函数错误
- 调用专用模板时出错"no matching function for call to [...]"
- EASTL矢量<向量<int>>连续的
- c++20[[no.unique_address]]中的新功能是什么
- 以线程安全的方式调用"QQuickPaintedItem::updateImage(const QImage&image)"(no QThread)
- "no matching function for call to 'Vector::Vector'"错误
- Android NDK clang 编译器错误在 Windows 上显示'No such file or directory'
- 处理"no operator found"
- 我在 ifstream input_file(文件名)行中收到错误"no matching function to call";
- 如何解决"no Qt platform plugin could be initialized"问题?
- "Unable to start debugging. No process is associated with this object." - 在Visual Studio Code中使用GDB
- 为什么当我在 std::string 中打开文件名的 fstream 时出现"no matching function"错误?
- 已解决 - C++ 的崇高文本中的"fatal error: opencv: no such file or directory"
- do while 循环中的 if 语句以 yes 或 no 结尾
- 从 TVector2 类派生复杂类:"No matching function for call to Complex::Complex()"
- 错误消息:使用"string* +="后"no match for 'operator+='"
- Eulers 项目问题 no 345 听不懂几行代码
- "No-Const Pointer to Const "调用功能
- 如何在 c++ 中将 s1 和 s2 与 no if 语句进行比较
- "No such file or directory" C++标头问题