【问题标题】:Error C++ : does not name a type [duplicate]错误 C++:没有命名类型 [重复]
【发布时间】:2016-01-24 22:30:47
【问题描述】:

我对下一个代码有疑问,我收到错误:“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];

【问题讨论】:

标签: c++ compiler-errors


【解决方案1】:

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

using namespace std; 

int *ptab;                     
bool *pfreeC;  

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

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

【讨论】:

  • 谢谢,之前看过很多例子,但是没看懂,,,,,
猜你喜欢
  • 1970-01-01
  • 2015-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多