我正在尝试编译下面的简单程序.但是,它没有编译并给出错误:
error C2065: 'cout' : undeclared identifier
Run Code Online (Sandbox Code Playgroud)
我想问你为什么这个程序不起作用虽然我已经包含iostream头文件了?
#include <iostream>
void function(int) { cout << “function(int) called” << endl; }
void function(unsigned int) { cout << “function(unsigned int) called” << endl; }
int main()
{
function(-2);
function(4);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
如果我忘记在 C++ 类中声明析构函数,谁能告诉我对象的内存会发生什么?我的意思是,它是被释放还是导致内存泄漏?示例或演示将不胜感激。
提前致谢。
我试图写它创建一个包含类的程序矢量指向成员函数,与add()和remove()成员函数.我写的代码是 -
1 #include <iostream>
2 #include <vector>
3 using namespace std;
4
5 typedef void(*classFuncPtr)();
6
7 class FunctionVectors
8 {
9 private:
10 vector<classFuncPtr> FunctionPointerVector;
11 public:
12 FunctionVectors(){}
13 void add(classFuncPtr funcPtr);
14 void remove(int index);
15 void run();
16 void a(){cout<<"a: Why are you calling me?"<<endl;}
17 };
18
19 void FunctionVectors::add(classFuncPtr funcPtr)
20 {
21 FunctionPointerVector.push_back(funcPtr);
22 }
23
24 void FunctionVectors::remove(int index)
25 {
26 FunctionPointerVector.erase(FunctionPointerVector.begin() + index); …Run Code Online (Sandbox Code Playgroud)