相关疑难解决方法(0)

可以std :: begin使用数组参数吗?如果可以,怎么做?

我在使用std::begin()std::end()(从iterator库中)使用c风格的数组参数时遇到了麻烦.

void SetOrigin(const double i_point[3]) {
  Vector v;
  std::copy(
    std::begin(i_point), 
    std::end(i_point), 
    v.begin());
  this->setOrigin(v);
}
Run Code Online (Sandbox Code Playgroud)

这导致Visual Studio 2010出现以下错误(类似于结束):

error C2784: '_Ty *std::begin(_Ty (&)[_Size])' : could not deduce template argument for '_Ty (&)[_Size]' from 'const double []'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(995) : see declaration of 'std::begin'
Run Code Online (Sandbox Code Playgroud)

将参数更改为非const会产生相同的结果.

尝试将参数指定为

...
std::begin<const double, 3>(i_point), 
std::end<const double, 3>(i_point),
...
Run Code Online (Sandbox Code Playgroud)

得到:

error C2664: '_Ty *std::begin<const double,3>(_Ty (&)[3])' : cannot convert parameter 1 from 'const double []' to …
Run Code Online (Sandbox Code Playgroud)

c++ arrays iterator stl std

14
推荐指数
1
解决办法
7503
查看次数

标签 统计

arrays ×1

c++ ×1

iterator ×1

std ×1

stl ×1