Я создал программу, которая использует динамический массив.Это работает, когда я использую свою функцию вставки и затем показываю элементы массивов, это показывает мне все, что я хочу.Проблема в том, что в конце программы он не возвращается со значением 0, но он блокируется на несколько секунд и говорит «Процесс завершен со значением 3221225477».Что случилось?
заголовок:
#ifndef VETTORE_H
#define VETTORE_H
#include "regalo.h"
typedef regalo T;
class vettore {
friend ostream& operator<<(ostream&,const vettore&);
friend istream& operator>>(istream&,vettore&);
private:
T *v;
int riemp;
int max;
public:
vettore();
vettore(const int);
~vettore(){delete [] v;};
bool full(){return riemp==max;};
bool empty()const;
bool inserisci(const T&);
T& operator[](const int index);
};
#endif
cpp файл:
#include "vettore.h"
ostream &operator<<(ostream& out,const vettore & v1){
for(int i=0;i<v1.riemp;i++){
out<<v1.v[i];
}
return out;
}
istream &operator>>(istream& in,vettore &v1){
for(int i=0;i<v1.riemp;i++){
in>>v1.v[i];
}
return in;
}
vettore::vettore(){
riemp=0;
max=10;
v=new T[max];
}
vettore::vettore(const int n):max(n),riemp(0){
v=new T[max];
}
bool vettore::empty()const{
if(riemp==0){
return true;
}else return false;
}
bool vettore::inserisci(const T& n){
if(max==0){
cout<<"Inserisci il massimo di elementi del vettore: ";
cin>>max;
}
if(!full()){
v[riemp]=n;
riemp++;
return true;
}else return false;
}
T& vettore::operator[](const int index){
return v[index];
}
основной файл:
#include "vettore.h"
int main(int argc, char** argv) {
int riempimento;
vettore vett(1);
regalo r1("Alex",300,"quadrato");
vett.inserisci(r1);
cout<<"Gli elementi del vettore sono: \n";
for(int i=0;i<riempimento;i++){
cout<<vett[i]<<endl;
}
system("PAUSE");
return 0;
}