相关疑难解决方法(0)

std :: valarray的运算符*有什么问题?

考虑下面的MCVE,其中有两个值数组,其中w两次是两次v在此处尝试):

#include <valarray>

using namespace std;

int main() {
  valarray<int> v { 1, 2, 3 };

  for ([[maybe_unused]] auto x : v) {} // Ok

  auto w = v * 2;     // Leads to failure in loop below
  //valarray<int> w = v * 2; // Works
  //auto w = v*=2;      // Works
  //auto w = v; w *= 2; // Works

  for ([[maybe_unused]] auto x : w) {} // Failure here
}
Run Code Online (Sandbox Code Playgroud)

这个例子在最后一个循环中用clang和gcc编译失败(这里是gcc输出):

error: …
Run Code Online (Sandbox Code Playgroud)

c++ operators language-lawyer c++11 valarray

11
推荐指数
1
解决办法
268
查看次数

标签 统计

c++ ×1

c++11 ×1

language-lawyer ×1

operators ×1

valarray ×1