Witam, prosiłbym o nakierowanie gdzie należy szukać błędu w projekcie C++ pisanym w VS 2010. Pod koniec działania programu ( w momencie kiedy powinna zadziałaś funkcja delete [] ) otrzymuję dany komunikat:
http://imageshack.us/photo/my-images/16/errorin.jpg/][IMG]http://img16.imageshack.us/img16/6929/errorin.jpg
Z projekcie posiadam plik nagłówkowy "bus.h"
#pragma once
#include <iostream>
#include <fstream>
#include <string>
#include "mytime.h"
using namespace std;
class bus
{
public:
bus(void);
~bus(void);
string Number;
short* Route;
mytime* DepHoursFromA;
mytime* DepHoursFromB;
void ShowDepHours(void);
private:
static short counter;
static short AmountOfBuses;
static string* BusNumbers;
short NumberOfStopovers;
short NumberOfDepA;
short NumberOfDepB;
bool HasRoute;
};
i plik właściwy "bus.cpp"
#include "bus.h"
short bus::counter = 0;
short bus::AmountOfBuses;
string* bus::BusNumbers;
bus::bus(void)
{
if( counter == 0 )
{
string BusFileName = "bus_numbers.txt";
ifstream BusFile( BusFileName.c_str() );
if( !BusFile )
{
cout << "Couldn't have found \"" << BusFileName << "\" file" << endl;
cin.get();
exit(1);
}
BusFile >> AmountOfBuses;
if( BusFile.fail() )
{
cout << "Couldn't have found integer indicating number of buses" << endl;
cin.get();
exit(1);
}
BusNumbers = new string[AmountOfBuses];
for( int i = 0; i < AmountOfBuses; i++ )
BusFile >> BusNumbers[i];
BusFile.close();
}
Number = BusNumbers[counter];
string FileName = BusNumbers[counter] + ".txt";
ifstream BusData( FileName.c_str() );
if( BusData.fail() )
{
cout << "Couldn't have found file with data for bus number "<< FileName << endl;
cin.get();
exit(1);
}
BusData >> NumberOfStopovers;
if( BusData.fail() )
{
cout << "Couldn't have found integer indicating number of stopovers for bus nr " << Number << endl;
cin.get();
exit(1);
}
Route = new short[NumberOfStopovers];
for( int i = 0; i < NumberOfStopovers; i++ )
BusData >> Route[i];
BusData >> NumberOfDepA;
DepHoursFromA = new mytime[NumberOfDepA];
for( int i = 0; i < NumberOfDepA; i++ )
BusData >> DepHoursFromA[i];
BusData >> NumberOfDepB;
DepHoursFromB = new mytime[NumberOfDepB];
for( int i = 0; i < NumberOfDepB; i++ )
BusData >> DepHoursFromB[i];
counter++;
}
bus::~bus(void)
{
delete [] BusNumbers;
delete [] Route;
delete [] DepHoursFromA;
delete [] DepHoursFromB;
}
W pliku "main.cpp" tworzę wskaźnik do dynamicznie alokowanej pamięci
bus* Buses = new bus[TG.GiveNrOfBuses()
i wszystko jest OK. Kiedy jednak wykonają się różne polecenia i powinna nastąpić instrukcja
delete [] Buses
to następuje wyżej wymieniony błąd.
W trakcie pisania miałem taką myśl, czy chodzi o to, że próbuję skasować już nieistniejące miejsca w pamięci skoro istnieje destruktor klasy, ale chciałbym aby ktoś biegły w programowaniu potwierdził moje przypuszczenia lub powiedział co może być źle w programie.