为什么函数的返回类型与实际句子不一致?
Why is the return type of the function not consistent with the actual sentence?
在程序中,它具有:
EnergyFunctional* ef;
ef->insertFrame(fh, &Hcalib);
该函数定义如下:
EFFrame* EnergyFunctional::insertFrame(FrameHessian* fh, CalibHessian* Hcalib)
{
EFFrame* eff = new EFFrame(fh);
eff->idx = frames.size();
frames.push_back(eff);
nFrames++;
fh->efFrame = eff;
assert(HM.cols() == 8*nFrames+CPARS-8); /// CPARS = 4
bM.conservativeResize(8*nFrames+CPARS);
HM.conservativeResize(8*nFrames+CPARS,8*nFrames+CPARS);
bM.tail<8>().setZero();
HM.rightCols<8>().setZero();
HM.bottomRows<8>().setZero();
EFIndicesValid = false;
EFAdjointsValid=false;
EFDeltaValid=false;
setAdjointsF(Hcalib);
makeIDX();
for(EFFrame* fh2 : frames)
{
connectivityMap[(((uint64_t)eff->frameID) << 32) + ((uint64_t)fh2->frameID)] = Eigen::Vector2i(0,0); /// move left 32 bits
if(fh2 != eff)
connectivityMap[(((uint64_t)fh2->frameID) << 32) + ((uint64_t)eff->frameID)] = Eigen::Vector2i(0,0); /// index is totally 64 bits, front 32 bits for each frame, rear 32 bits for current frame
}
return eff;
}
似乎返回类型应该是无效的,以便它可以与最后一句保持一致......
我还检查了是否有其他同名的"inserFrame"函数,但没有。
这个程序可以编译成功,但是为什么可以没有问题呢?
函数指定的返回类型是EFFrame*
,它是指向EFFrame
对象的指针。函数返回的值是eff
,这也是一个EFFrame*
类型的指针。所以不应该有任何混淆。
如果不返回值,则仅在函数声明中使用void
返回类型。但是,如最后一行所示,此函数显然试图返回指向EFFrame
对象的指针。
但是,即使在具有明确定义的返回类型的函数中,也可能不需要使用该值。因此,从技术上讲,只调用函数而不将返回值存储到变量中是合法的。因此,即使ef->insertFrame(fh, &Hcalib);
调用函数并返回EFFrame*
指针,它也不会被存储。
相关文章:
- 大于65535的C++数组[size]引发不一致的溢出
- 在 C++(和 C)中进行类型转换时明显不一致
- 填充上编译器生成的复制构造函数之间的不一致
- 犰狳的 print() 方法和 cout 在从 Rcpp 调用时顺序不一致
- CreateDIBSection为同一图像返回不一致的位图位值
- 在 Qml 中从 QSqlTableModel 中删除单行时视图不一致
- 模板参数推导不一致
- 声明中不一致的no是否违反ODR?
- 如何删除分支因子不一致的树,最大为 30,40
- 从 C++ 函数与 Python 函数返回的不一致值用于偏斜正态分布
- 从 C 字符串构造 std::string 与从另一个 std::string 构造 std::string 不一致
- 这种比较是否不一致(或者存在其他问题)?
- 以下可变参数模板行为是否不一致?
- 如何修复我的链表读数不一致的问题?
- 在C++17中,为什么类模板和函数模板的指针类型推导明显不一致
- void 函数中的指针参数返回不一致的值
- 如何查找导致结果不一致的代码
- 跨平台 mySQL 与字符集不一致
- C++:不一致的 std::p ow( 类型 ) 定义
- 为什么函数的返回类型与实际句子不一致?