gpt4 book ai didi

c# - C# Action += function 的 C++ 方式?

转载 作者:太空狗 更新时间:2023-10-29 20:05:35 27 4
gpt4 key购买 nike

在 C# 中我们可以说:

Action act = ()=> {/*stuff*/}; 
act += ()=> {/*another stuff*/}`

然后调用act()

我想知道如何在 C++ 中做这样的事情(现在使用 lambda 它将非常有用,如果可能的话不使用 Boost/Qt 信号)?

最佳答案

也许用 std::functions:

std::vector<std::function<void()>> act;

act.emplace_back([] { /* stuff */ });
act.emplace_back([] { /* more stuff */ });

调用:

for (auto & f : act) { f(); }

关于c# - C# Action += function 的 C++ 方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12451554/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com