c++ - 错误 C++ : does not name a type

标签 c++ compiler-errors

<分区>

我在下一段代码中遇到了问题,我收到错误:'ptab' 没有命名类型,'pfreeC' 没有命名类型,我不知道如何解决,感谢您的帮助 = )

#include <iostream> 
#include <cstdlib>
#include <ctime> 
#include <conio.h>
#include <iomanip>
#include <stdio.h>
#include <Windows.h>

using namespace std; 
int *ptab;                     //Here is the error
ptab=new int[64]; 

bool *pfreeC;             //Here is the error
pfreeC=new bool[11];

最佳答案

问题是你的代码在函数体之外

using namespace std; 

int *ptab;                     
bool *pfreeC;  

int main()
{
   ptab = new int[64];
   pfreeC = new bool[11];
   return 0;
}

当然你也应该删除分配的内存。或者更好的是,使用智能指针。

关于c++ - 错误 C++ : does not name a type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33335341/

相关文章:

java - 为什么我会收到以下错误以及空构造函数中应该有什么?

c++ - 通过套接字发送结构;服务器和客户端在同一台机器上

c++ - 处理跨平台用户认证和授权的策略

c++ - 在全局函数中获取对象地址或 NULL 的统一方法

c++ - 为什么这个程序被三个 C++ 编译器错误地拒绝了?

c++ - 在Vector类对象上调用push_back()方法时收到错误

c - 为什么我在 C 程序中收到杂散 '342' 错误?

c++ - 防止在返回时复制对象

C++ 与其他语言互操作

mysql - 错误代码 : 1648. 条件项 'MESSAGE_TEXT' 的数据太长