c++中的右值引用
Rvalue references in g++
我正在将编译器从Visual Studio更改为g++,并且在函数参数中通过引用传递有一些问题。
在Visual Studio中,函数是:
void Foo(int&a, int&b)
使得a, b在这个函数中被修改。因此,我不能在g++
void Foo(const int&a, const int &b)
并且在我的g++中也不允许右值引用:
void Foo( int&& a, int&& b)
那么使用指针是转换代码的唯一方法吗?
void Foo( int* a, int* b)
p/S:这是用g++编译时的错误:
error: no matching function for call to ‘Steerable::buildSCFpyrLevs(Tensor<double, 2ul>, std::vector<Tensor<double, 2ul> >&, int&, int&, int&, bool&)’
Steerable.cpp:63:100: note: candidate is:
Steerable.h:93:7: note: void Steerable::buildSCFpyrLevs(Steerable::data_ref, std::vector<Tensor<double, 2ul> >&, int, int, int, bool)
Steerable.h:93:7: note: no known conversion for argument 1 from ‘Tensor<double, 2ul>’ to ‘Steerable::data_ref {aka Tensor<double, 2ul>&}’
函数声明如下:
typedef Tensor<value_type,2> data_type;
typedef data_type& data_ref;
vector<Steerable::data_type>& Steerable::buildSCFpyr(Steerable::c_data_ref im, int nLevel, int nDir, int twidth, bool subsample)
出现错误的行:
buildSCFpyrLevs(imdft.FreqComplexFilter(toComplex(lo0mask)),pyr_freq,nLevel,nDir,twidth, subsample);
FreqComplexFilter
可能没有通过引用返回。
Tensor<double, 2> tempVal = imdft.FreqComplexFilter(toComplex(lo0mask));
buildSCFpyrLevs(tempVal, pyr_freq, nLevel, nDir, twidth, subsample);
这是肮脏的,因为它只是使代码编译,它不解决潜在的设计问题(问题是为什么buildSCFpyrLevs
正在修改FreqComplexFilter
返回的临时值)。
相关文章:
- 将对象数组的引用传递给函数
- 什么时候在C++中返回常量引用是个好主意
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 何时在引用或唯一指针上使用移动语义
- 如何在c++中使用引用实现类似python的行为
- 编译C++时未定义的引用
- Ctypes wstring通过引用传递
- c++r值引用应用于函数指针
- 理解c++中的引用
- C++取消引用指针.为什么会发生变化
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- 强制转换为引用类型
- 引用一个已擦除类型(void*)的指针
- 向量元素的引用地址与它所指向的向量元素的地址不同.为什么
- 具有默认值的引用获取函数
- 如何使用基类指针引用派生类成员
- 使用取消引用的指针的多态性会产生意外的结果.为什么?
- 如何引用基类的派生类?