F
Fredda
Hello!
I have problem with the following:
..
..
..
Transaktion :: Transaktion(const Transaktion &t)
: typ(t.typ), datum(t.datum), namn(t.namn), belopp(t.belopp),
ant_kompisar(t.ant_kompisar)
{
if (ant_kompisar > 0) {
kompisar = new string[ant_kompisar];
for (int i = 0; i < ant_kompisar; i++)
kompisar = t.kompisar;
}
else
kompisar = 0;
}
..
..
..
bool Transaktion :: finnsKompis(string namnet) {
for (int i = 0; i < ant_kompisar; i++)
if (kompisar == namnet)
return true;
return false;
}
..
..
..
..
..
..
double TransaktionsLista :: aerSkyldig(string namnet) {
double belopp = 0.0;
for (int i = 0; i < antalTrans; i++) {
Transaktion temp = Transaktion(trans);
if ( temp.finnsKompis(namnet) )
belopp += ( trans.haemta_belopp() /
(trans.haemta_ant_kompisar() + 1) );
}
return belopp;
}
..
..
..
I want to use the method finnsKompis(string namnet) from the class
'Transaktion' on a Transaktion-object in the class 'TransaktionsLista'.
The code compiles fine but generates an error on runtime. I suspect it
has
something to do with the matrix 'kompisar[]' in the
'Transaktion'-class but I don't understand what's wrong. I do use a
copy-constructor in the class 'Transaktion' but it doesn't seem to
help.
I'm very greatful for any suggestions!
Thanks in advance!
Fredrik
PS. I'm sorry that the code is in swedish...
I have problem with the following:
------------------------------------------------------------------------------------------------------From the class 'Transaktion':
..
..
..
Transaktion :: Transaktion(const Transaktion &t)
: typ(t.typ), datum(t.datum), namn(t.namn), belopp(t.belopp),
ant_kompisar(t.ant_kompisar)
{
if (ant_kompisar > 0) {
kompisar = new string[ant_kompisar];
for (int i = 0; i < ant_kompisar; i++)
kompisar = t.kompisar;
}
else
kompisar = 0;
}
..
..
..
bool Transaktion :: finnsKompis(string namnet) {
for (int i = 0; i < ant_kompisar; i++)
if (kompisar == namnet)
return true;
return false;
}
..
..
..
------------------------------------------------------------------------------------------------------From the class 'TransaktionsLista':
..
..
..
double TransaktionsLista :: aerSkyldig(string namnet) {
double belopp = 0.0;
for (int i = 0; i < antalTrans; i++) {
Transaktion temp = Transaktion(trans);
if ( temp.finnsKompis(namnet) )
belopp += ( trans.haemta_belopp() /
(trans.haemta_ant_kompisar() + 1) );
}
return belopp;
}
..
..
..
I want to use the method finnsKompis(string namnet) from the class
'Transaktion' on a Transaktion-object in the class 'TransaktionsLista'.
The code compiles fine but generates an error on runtime. I suspect it
has
something to do with the matrix 'kompisar[]' in the
'Transaktion'-class but I don't understand what's wrong. I do use a
copy-constructor in the class 'Transaktion' but it doesn't seem to
help.
I'm very greatful for any suggestions!
Thanks in advance!
Fredrik
PS. I'm sorry that the code is in swedish...