What is the role of c in the context of an operator?

2026-04-28 04:041阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计400个文字,预计阅读时间需要2分钟。

What is the role of c in the context of an operator?

我很难理解代码中函数调用的顺序。我期待看到下面的输出:A1B2。然而,我可以看到我得到的输出是BA12。这表明函数调用是按照从右到左的顺序进行的:std::cout < 我很难理解下面代码中的调用顺序.
我期待看到下面的输出

A1B2

虽然我可以看到我得到的输出是

BA12

我以为调用std :: cout<< b-> fooA()<< b-> fooB()<< std :: endl等同于调用

std::cout.operator<<( b->fooA() ).operator<< ( b->fooB() )

但我可以看到情况并非如此.你能帮助我更好地理解它是如何工作的以及与全球操作符的关系<<?这是最后一次调用这个序列吗? 问候 AFAG

#include <iostream> struct cbase{ int fooA(){ std::cout<<"A"; return 1; } int fooB(){ std::cout <<"B"; return 2; } }; void printcbase(cbase* b ){ std::cout << b->fooA() << b->fooB() << std::endl; } int main(){ cbase b; printcbase( &b ); } 编译器可以像这样评估printcbase()函数:

void printcbase(cbase* b ){ int a = b->FooA(); // line 1 int b = b->FooB(); // line 2 std::cout << a; // line 3 std::cout << b; // line 4 stc::cout << std::endl; }

或者标记为1 – 4的许多线条的一些.只保证第1行在第3行之前完成,第2行在第4行之前完成(当然第4行在第4行之前).标准没有说更多,实际上你可以期望使用不同的C编译器得到不同的结果.

What is the role of c in the context of an operator?

本文共计400个文字,预计阅读时间需要2分钟。

What is the role of c in the context of an operator?

我很难理解代码中函数调用的顺序。我期待看到下面的输出:A1B2。然而,我可以看到我得到的输出是BA12。这表明函数调用是按照从右到左的顺序进行的:std::cout < 我很难理解下面代码中的调用顺序.
我期待看到下面的输出

A1B2

虽然我可以看到我得到的输出是

BA12

我以为调用std :: cout<< b-> fooA()<< b-> fooB()<< std :: endl等同于调用

std::cout.operator<<( b->fooA() ).operator<< ( b->fooB() )

但我可以看到情况并非如此.你能帮助我更好地理解它是如何工作的以及与全球操作符的关系<<?这是最后一次调用这个序列吗? 问候 AFAG

#include <iostream> struct cbase{ int fooA(){ std::cout<<"A"; return 1; } int fooB(){ std::cout <<"B"; return 2; } }; void printcbase(cbase* b ){ std::cout << b->fooA() << b->fooB() << std::endl; } int main(){ cbase b; printcbase( &b ); } 编译器可以像这样评估printcbase()函数:

void printcbase(cbase* b ){ int a = b->FooA(); // line 1 int b = b->FooB(); // line 2 std::cout << a; // line 3 std::cout << b; // line 4 stc::cout << std::endl; }

或者标记为1 – 4的许多线条的一些.只保证第1行在第3行之前完成,第2行在第4行之前完成(当然第4行在第4行之前).标准没有说更多,实际上你可以期望使用不同的C编译器得到不同的结果.

What is the role of c in the context of an operator?