Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++中指向对象的指针 我试图通过一个简单的车辆路径问题来获取C++指针和对象的挂起。即使我的代码目前正在运行,我也无法摆脱我的方法完全错误的感觉。让我头疼的是一些代码片段,例如: std::map<const Route*, double>::iterator it = quantities.begin(); if ((*(*(it->first)).getDestination()).getDemand() > (*(*(it->first)).getDeparture()).getSupply())_C++_Oop_Pointers - Fatal编程技术网

C++中指向对象的指针 我试图通过一个简单的车辆路径问题来获取C++指针和对象的挂起。即使我的代码目前正在运行,我也无法摆脱我的方法完全错误的感觉。让我头疼的是一些代码片段,例如: std::map<const Route*, double>::iterator it = quantities.begin(); if ((*(*(it->first)).getDestination()).getDemand() > (*(*(it->first)).getDeparture()).getSupply())

C++中指向对象的指针 我试图通过一个简单的车辆路径问题来获取C++指针和对象的挂起。即使我的代码目前正在运行,我也无法摆脱我的方法完全错误的感觉。让我头疼的是一些代码片段,例如: std::map<const Route*, double>::iterator it = quantities.begin(); if ((*(*(it->first)).getDestination()).getDemand() > (*(*(it->first)).getDeparture()).getSupply()),c++,oop,pointers,C++,Oop,Pointers,及 我是否完全偏离了轨道,我是否遗漏了什么,或者这种情况是否正常?而不是*p.x写p->x。而不是*p.x写p->x。要提高可读性,可以将*s改为->: 此外,如果您不打算放弃该对象的所有权,而且您也不打算放弃,那么在这种情况下,最好通过常量引用返回: const Departure& Route::getDeparture() const { return *departure; }; 并使用,而不是->: 要增加可读性,可以将*s更改为->: 此外,如果您不打算放弃该对象的所有


我是否完全偏离了轨道,我是否遗漏了什么,或者这种情况是否正常?

而不是*p.x写p->x。

而不是*p.x写p->x。

要提高可读性,可以将*s改为->:

此外,如果您不打算放弃该对象的所有权,而且您也不打算放弃,那么在这种情况下,最好通过常量引用返回:

const Departure& Route::getDeparture() const {
  return *departure;
};
并使用,而不是->:


要增加可读性,可以将*s更改为->:

此外,如果您不打算放弃该对象的所有权,而且您也不打算放弃,那么在这种情况下,最好通过常量引用返回:

const Departure& Route::getDeparture() const {
  return *departure;
};
并使用,而不是->:


只需将链作为迭代器->成员->方法1->方法2等等?并将链作为迭代器->成员->方法1->方法2等等?
if(it->first->getDestination()->getDemand() > it->first->getDeparture()->getSupply())
const Departure& Route::getDeparture() const {
  return *departure;
};
if(it->first->getDestination().getDemand() > it->first->getDeparture().getSupply())