當我運行這個主要功能,後「系統(」暫停「);」程序退出並返回值:3221226356.有沒有人可以告訴我爲什麼? 主:進程退出返回值:3221226356
int main(int argc, char** argv)
{
int righe, colonne;
cout<<"-> Rows : ";
cin>>righe;
cout<<"-> Columns: ";
cin>>colonne;
Matrice<int> matrice(righe,colonne);
//no problems if declared as pointer
/*Matrice<int> *matrice;
matrice = new Matrice<int>(righe,colonne);*/
delete &matrice;
//delete matrice;
system("PAUSE");
return 0;
}
我有這個C++類:
template <typename T>
class Matrice{
private:
int righe;
int colonne;
T **elementi;
public:
Matrice(int righe, int colonne);
};
的調用的構造函數:
template <typename T>
Matrice<T>::Matrice(int r, int c)
{
righe = r;
colonne = c;
elementi = new T*[righe];
for(int i=0;i<righe;i++) elementi[i] = new T[colonne];
}
被叫析構函數:
template <typename T>
Matrice<T>::~Matrice()
{
for(int i=0; i<righe; i++) delete[] elementi[i];
delete[] elementi;
delete &righe;
delete &colonne;
}
如果我聲明我目的作爲指針並不存在問題!
是否'Matrice'有析構函數?如果是這樣,它是如何編碼的? – NathanOliver
編輯問題! – 2017-10-17 17:56:27
你怎麼知道程序退出3221226356? – 2017-10-17 17:57:28