C++ "?>"运算符

C++ "?>" operator

本文关键字:运算符 gt C++      更新时间:2023-10-16

谁能给我解释一下这种操作符

这是什么?>
在c++中做什么?

使用它的代码示例:

#include <iostream>
#include <string>
using namespace std;
class A {
  public:
    int x;
};
class B : public A {
  public:
    B() {x=1;}
    B(int x) {this?>x = x;}
};
int main()
{
  B c1;
  B c2(10);
  cout << c1.x;
  cout << c2.x;
  return 0;
}

我认为你试图说->,因为?>不存在。

在上下文中,我确定您想要->

你可能在打字的时候出错了。PD:尝试编译前问

这是一个打字错误。你可能想参考->
this操作符用于访问调用该函数的对象的属性,->操作符用于访问该对象的属性。