C++带有命令的 VBA 版本,用于更优雅的代码

C++ version of VBA's with command for more elegant code

本文关键字:用于 代码 版本 命令 VBA C++      更新时间:2023-10-16

我是用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++语句:它只是没有必要,引用可以减少歧义。