我正在用 C++ 编写:
returner.token[0].type = "a";
returner.token[0].fQF = "b";
returner.token[0].val = "c";
returner.token[0].pos = "d";
returner.token[0].emit = "e";
在VBA中,你可以这样写:
with returner.token[0]
.type = "a"
.fQf = "b"
.val = "c"
.pos = "d"
.emit = "e"
end with
C++ 中是否内置了类似的功能?
谢谢!
最佳答案
您正在寻找引用。
auto& r = returner.token[0];
r.type = "a";
r.fQF = "b";
r.val = "c";
r.pos = "d";
r.emit = "e";
在这里可以帮助您的其他机制包括定义适当的构造函数,以及使用大括号初始化列表(如果适用)。
没有像 Visual Basic with
这样的 C++ 语句:它只是没有必要,引用可以更明确地完成这项工作。
关于C++ 版本的 VBA,带有更优雅代码的命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31714931/