Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.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+中访问两个函数的单个对象+;_C++ - Fatal编程技术网

C++ 在c+中访问两个函数的单个对象+;

C++ 在c+中访问两个函数的单个对象+;,c++,C++,这段代码在做什么 SNMP_Sequence trapseq=trap.GetPDU().GetVarBindList() 据我所知,一个对象一次只能引用一个成员函数。 这里发生了什么? trap.GetPDU().GetVarBindList()trap.GetPDU()返回一个对象,并对该对象调用GetVarBindList() trap.GetPDU().GetVarBindList() 相当于: obj.GetVarBindList() 其中,obj是由trap.GetPDU()返回

这段代码在做什么

SNMP_Sequence trapseq=trap.GetPDU().GetVarBindList()

据我所知,一个对象一次只能引用一个成员函数。 这里发生了什么?
trap.GetPDU().GetVarBindList()
trap.GetPDU()
返回一个对象,并对该对象调用
GetVarBindList()

trap.GetPDU().GetVarBindList()
相当于:

obj.GetVarBindList()
其中,
obj
是由
trap.GetPDU()返回的对象

这也称为

陷阱。GetPDU()
返回一个对象,并对该对象调用
GetVarBindList()

trap.GetPDU().GetVarBindList()
相当于:

obj.GetVarBindList()
其中,
obj
是由
trap.GetPDU()返回的对象


这也称为

它检索
GetPDU
返回的对象(或引用),然后对其调用
GetVarBindList

相当于:

SomeObject &PDU = trap.GetPDU();
SNMP_Sequence trapseq = PDU.GetVarBindList();

它检索
GetPDU
返回的对象(或引用),然后对其调用
GetVarBindList

相当于:

SomeObject &PDU = trap.GetPDU();
SNMP_Sequence trapseq = PDU.GetVarBindList();

对任何表达式的结果调用成员函数是完全合法的,包括对另一个成员的访问,如果该表达式是适当的类型

std::vector<std::vector<std::vector<std::string>>> super_jaggy;
// insert stuff here
std::cout << super_jaggy.front().front().front().size(); // legal
std::vector super_jaggy;
//在这里插入内容

std::cout在任何表达式的结果上调用成员函数是完全合法的,包括对另一个成员的访问,如果该表达式是适当的类型

std::vector<std::vector<std::vector<std::string>>> super_jaggy;
// insert stuff here
std::cout << super_jaggy.front().front().front().size(); // legal
std::vector super_jaggy;
//在这里插入内容

如果
GetPDU
是右值或常量引用,则std::不一定。如果
GetPDU
是右值或常量引用,则std::不一定。需要澄清的是,
trap.GetPDU()
可能返回对象或引用。进一步用于调用方法
GetVarBindList()
trap.GetPDU()
可能返回一个对象或引用。并进一步用于调用方法
GetVarBindList()