Arduino equivalent to VB WITH

Arduino equivalent to VB WITH

本文关键字:WITH VB to equivalent Arduino      更新时间:2023-10-16

是否有一个Arduino等同于Visual BASIC"with"概念?

如果我有和 Arduino 结构如下:

typedef struct {
  int present = 0; // position now
  int demand = 0;  // required position
} superStruct;
superStruct super;

我可以说

if (super.present > super.demand) { super.present-=1; }

有没有办法我可以将其缩短为

with super {
  if (.present > .demand) { .present-=1; }
}

谢谢!

只是为了补充John Bode的答案:请注意,结构体¹可以访问不带前缀的成员:

struct superStruct {
  int present = 0; // position now
  int demand = 0;  // required position
  void update_position() {
    if (present > demand) { present-=1; }
  }
};
superStruct super;
super.update_position();
¹默认情况下,

C++ 中的结构只是一个所有成员都公开的类。

C++中没有等效的语法;必须指定struct实例以及成员。