2015-10-25 49 views
0

我有一個與下一個代碼的問題,我得到的錯誤:'ptab'沒有命名一個類型和'pfreeC'沒有命名一個類型,我不明白如何解決這個問題,感謝您的幫助=)錯誤C++:不會命名一個類型

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

http://stackoverflow.com/questions/16938810/does-not-name-a-type-error-in-c –

回答

1

的問題是,你有代碼的函數體

using namespace std; 

int *ptab;      
bool *pfreeC; 

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

當然,你也應該刪除分配的內存之外。甚至更好,使用智能指針。

+0

謝謝,我以前看過很多例子,但我不明白, ,,, – user153489