Witam, problem brzmi następująco: Program się kompiluje, wszystko działa, ale powiedzmy za 10 czy n'ta kompilacją (bez zmieniania niczego) wyskakuje raport o błędach w miejscu wstawiania nowego obiektu. Wyrzuca błąd przy dodawaniu drugiego Workera.
Plik main:
#include <iostream>
#include "Client.h"
#include "Worker.h"
#include "Trip.h"
#include "TravelAgency.h"
#include "WorkerToClient.h"
using namespace std;
int main(int argc, char** argv)
{
TravelAgency test;
test.printClients();
test.printWorkers();
test.printTrips();
test.insert_Client(1,"Adam","Adamowski",20.00, 1,2);
test.insert_Client(2,"Kazimierz","Romoowski",20.00, 1,2);
test.insert_Client(3,"Patryk","Grzesiowski",20.00, 1,2);
test.insert_Client(4,"Fernardo","Zlotopolski",20.00, 1,2);
test.insert_Client(5,"Bonifacy","Kozlowski",20.00, 1,2);
test.insert_Client(6,"Kleofas","Orzelki",20.00, 1,2);
test.insert_Client(7,"Leopold","Maselkowski",20.00, 1,2);
test.insert_Client(8,"Amika","Korski",20.00, 1,2);
test.insert_Client(9,"Steve","Bolewicz",20.00, 1,2);
test.insert_Trip(1,"Alaska",2500,1700.50,15);
test.insert_Trip(2,"Tunezja",2700,720.39,59);
test.insert_Trip(3,"Krym",2000,913.40,50);
test.insert_Worker("Aleksander","Brzeczyszczykiewicz",15,20);
test.insert_Worker("Derrick","Rose",15,20);
test.printClients();
test.printWorkers();
test.printTrips();
// test.printWorkers();
//system("pause");
return 0;
}
konstruktor:
#include<iostream>
#include<cstring>
#include"Worker.h"
using namespace std;
Worker::Worker(char *n, char *ln, int p, int i)
{
name = new char (strlen(n));
id=i;
strcpy(name, n);
lname = new char (strlen(ln));
strcpy(lname, ln);
sold = 0;
proc = p;
earn = 0;
next=NULL;
cout<< "Making Worker "<<endl;;
}
lista:
void TravelAgency::insert_Worker(char *n, char *ln, int p, int i)
{
Worker *nowy;
nowy = new Worker(n,ln,p,i);
if(whead==0)
whead=nowy;//first element insertion.
else
{
Worker *temp=whead;
while(temp->getNEXT())
{
temp=temp->getNEXT();
cout<<"elo";
}
temp->setNEXT(nowy);
nowy->setNEXT(0);
}
}
grzesiek51114std::list
?grzesiek51114list<T>
albo zrobi swój własny kontenercustom<T>
- jak będzie chciał tak zrobi :)