P
Piotre Ugrumov
Excuse me for the previous post, I have tried to modify the classes of the
Savannah example and now I succeed to compile the classes but I have a
strange problem.
When I declar an object of the class Savan, I cannot see the methdo of the
class:
Savan s();
Leone l(........);
s.addLeone(l);
the methdo addLeone() isn't view, but all the method of the class Savan
aren't view.
//Savan s();
//s.addLeone(l);
error C2228: the element on the left ".addLeone" must have a type class,
structure or union
the type is "overloaded-function"
Why this behaviour?
If I define a constructor like this Savan(Leone &l, Zebra &z), I can view
and I can use all the methods.
//Savan s(l, z);
//s.addLeone(d);
In this way I don't receiver message error, but When I start the program all
is blocked
This constructor is implemented in this way:
Savan::Savan(Leone &l, Zebra &z){
addLeone(l);
addZebra(z);
}
Another question:
How can I do to add an object to a dynamic array:
I have defined 2 pointer and two int:
Leone *lPtr;
Zebra *zPtr;
int lsize, zsize;
For add an object to lPtr or zPtr, I have defined the method in this way:
void Savan::addLeone(Leone &l){
Leone *tmp;
tmp=lPtr;
lsize=lsize+1;
lPtr=new Leone[lsize];
lPtr=tmp;
lPtr[lsize-1]=l;
delete[] tmp;
}
Is correct what I write?
The constructor without arguments inizialize lPtr=0; zPtr=0; lsize=0;
zsize=0;
Thanks and excuse me.
Savannah example and now I succeed to compile the classes but I have a
strange problem.
When I declar an object of the class Savan, I cannot see the methdo of the
class:
Savan s();
Leone l(........);
s.addLeone(l);
the methdo addLeone() isn't view, but all the method of the class Savan
aren't view.
//Savan s();
//s.addLeone(l);
error C2228: the element on the left ".addLeone" must have a type class,
structure or union
the type is "overloaded-function"
Why this behaviour?
If I define a constructor like this Savan(Leone &l, Zebra &z), I can view
and I can use all the methods.
//Savan s(l, z);
//s.addLeone(d);
In this way I don't receiver message error, but When I start the program all
is blocked
This constructor is implemented in this way:
Savan::Savan(Leone &l, Zebra &z){
addLeone(l);
addZebra(z);
}
Another question:
How can I do to add an object to a dynamic array:
I have defined 2 pointer and two int:
Leone *lPtr;
Zebra *zPtr;
int lsize, zsize;
For add an object to lPtr or zPtr, I have defined the method in this way:
void Savan::addLeone(Leone &l){
Leone *tmp;
tmp=lPtr;
lsize=lsize+1;
lPtr=new Leone[lsize];
lPtr=tmp;
lPtr[lsize-1]=l;
delete[] tmp;
}
Is correct what I write?
The constructor without arguments inizialize lPtr=0; zPtr=0; lsize=0;
zsize=0;
Thanks and excuse me.