错误C ++:未命名类型 [英] Error C++ : does not name a type

查看:58
本文介绍了错误C ++:未命名类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的下一个代码有一个问题,出现错误:"ptab"未命名类型,"pfreeC"未命名类型,我不知道如何解决,谢谢您的帮助=)

I have a ploblem with the next code, I get the error: 'ptab' does not name a type and 'pfreeC' does not name a type, I don't understand how to solve that, thanks for your help =)

#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];

推荐答案

问题是您在函数体内有代码

The problem is that you have code outside a function body

using namespace std; 

int *ptab;                     
bool *pfreeC;  

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

当然,您还应该删除分配的内存.甚至更好,请使用智能指针.

Of course you should also delete the allocated memory. Or even better, use smart pointers.

这篇关于错误C ++:未命名类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆