未能调用函数列表中的函数 我有一个C++代码,它存储一个列表中的2个函数,然后调用内部列表: #include <string> #include <queue> #include <list> #include <map> #include <vector> #include <utility> #include <iostream> #include <thread> #include <Windows.h> #include <stdio.h> using namespace std; typedef void (*fp)(); void simpletest1(){ cout << "test1"; } void simpletest2(){ cout << "test2"; } int main() { list<fp> generalHandlers; generalHandlers.push_back(simpletest1); generalHandlers.push_back(simpletest2); for (auto it = generalHandlers.begin(); it != generalHandlers.end(); ++it){ (*it)(); } return 0; } #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 使用名称空间std; typedef void(*fp)(); void simpletest1(){ cout

未能调用函数列表中的函数 我有一个C++代码,它存储一个列表中的2个函数,然后调用内部列表: #include <string> #include <queue> #include <list> #include <map> #include <vector> #include <utility> #include <iostream> #include <thread> #include <Windows.h> #include <stdio.h> using namespace std; typedef void (*fp)(); void simpletest1(){ cout << "test1"; } void simpletest2(){ cout << "test2"; } int main() { list<fp> generalHandlers; generalHandlers.push_back(simpletest1); generalHandlers.push_back(simpletest2); for (auto it = generalHandlers.begin(); it != generalHandlers.end(); ++it){ (*it)(); } return 0; } #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 使用名称空间std; typedef void(*fp)(); void simpletest1(){ cout,c++,C++,它对我有效,尽管我用“std::vector”替换了“list”。也许你只是没有注意到输出,因为你没有在cout语句后添加“endl”?它对我有效,尽管我用“std::vector”替换了“list”。也许你只是没有注意到输出,因为你没有在cout语句后添加“endl”?code完全有效,因此问题在别处; 也许你应该在程序退出之前暂停它,这样你才能真正读取输出中的内容。同样,用std::endl刷新cout缓冲区也会有所帮助。代码完全有效,所以问题出在别处; 也许您应该尝试在程序退出之前暂停程序

它对我有效,尽管我用“std::vector”替换了“list”。也许你只是没有注意到输出,因为你没有在cout语句后添加“endl”?

它对我有效,尽管我用“std::vector”替换了“list”。也许你只是没有注意到输出,因为你没有在cout语句后添加“endl”?

code完全有效,因此问题在别处;

也许你应该在程序退出之前暂停它,这样你才能真正读取输出中的内容。同样,用
std::endl
刷新
cout
缓冲区也会有所帮助。

代码完全有效,所以问题出在别处;

也许您应该尝试在程序退出之前暂停程序,以便您可以实际读取输出中的内容。同时,使用
std::endl
刷新
cout
缓冲区也会有所帮助。

您需要刷新输出缓冲区。请尝试以下任一操作:

void simpletest1(){
    cout << "test1" << endl;
}

void simpletest2(){
    cout << "test2" << endl;
}

您需要刷新输出缓冲区。请尝试:

void simpletest1(){
    cout << "test1" << endl;
}

void simpletest2(){
    cout << "test2" << endl;
}

你试过刷新输出缓冲区吗?哦,它工作了!代码没有任何错误。你使用的IDE是什么?试一下代码块,它在程序终止后会保持屏幕。你的代码在我的设置中工作得很好。我只是使用终端和升华文本,谢谢大家的建议,这段代码现在对我非常有效。提示任何有类似问题的人:始终调用endl刷新输出,以便在程序仍在运行时看到打印出来的调试信息。是否尝试刷新输出缓冲区?哦,成功了!代码没有错误。您使用的IDE是什么?尝试代码块,它在程序终止后保持屏幕。您的代码工作正常在我的设置中。我正在使用terminal和sublime text,谢谢大家的建议,这段代码现在非常适合我。有类似问题的提示:始终调用endl刷新输出,以便在程序仍在运行时可以看到打印出的调试信息