P
Piotre Ugrumov
I have declared some function virtual, but when I call this function I have
errors.
In a class Simulator I have defined this:
Nave *navi[20];
The virtual function is the function modifica().
I call this function in this way: navi->modifica();
In this way, the function work correctly.
But in another class Simulator I have defined:
Veicolo *veicoli;
The Virtual function of Veicolo is colled modifica() too.
If I call this function in this way:
veicoli->modifica();
I receive this error:
error C2819: il tipo "Veicolo" has not a member"operator ->" of overload
see the declaration of "Veicolo"
Would you use"."?
error C2227: the element on the left of "->modifica" must point to a class,
structure o union
the type is "Veicolo"
Would you use"."?
If I call the function in this way:
veicoli.modifica();
The compiler doesn't give me error, but I don't use the virtual function.
The array of veicolo contain object of class tha derive from veicolo like
Auto and Moto.
When I call modifica in this way I use the function modifica of veicolo, but
not the function modifica() of Auto or Moto.
Whay this behaviour?
In the example of Nave the virtual function modifica() works correctly.
The last thing, I have defined this:
char *name;
and the method:
void Person::setName(char *n){
int i=static_cast<int>(strlen(n));
noae = new char[i+1];
strcpy(nome, n);
}
char* Person::getName()const{
return nome;
}
This function work correctly but if I define:
char name[20];
I cannot declare the function getName const, if I try to do thsi thing I
receive this error:
impossible to convert char[10] to char*, how can I resolve this error?
Thanks.
errors.
In a class Simulator I have defined this:
Nave *navi[20];
The virtual function is the function modifica().
I call this function in this way: navi->modifica();
In this way, the function work correctly.
But in another class Simulator I have defined:
Veicolo *veicoli;
The Virtual function of Veicolo is colled modifica() too.
If I call this function in this way:
veicoli->modifica();
I receive this error:
error C2819: il tipo "Veicolo" has not a member"operator ->" of overload
see the declaration of "Veicolo"
Would you use"."?
error C2227: the element on the left of "->modifica" must point to a class,
structure o union
the type is "Veicolo"
Would you use"."?
If I call the function in this way:
veicoli.modifica();
The compiler doesn't give me error, but I don't use the virtual function.
The array of veicolo contain object of class tha derive from veicolo like
Auto and Moto.
When I call modifica in this way I use the function modifica of veicolo, but
not the function modifica() of Auto or Moto.
Whay this behaviour?
In the example of Nave the virtual function modifica() works correctly.
The last thing, I have defined this:
char *name;
and the method:
void Person::setName(char *n){
int i=static_cast<int>(strlen(n));
noae = new char[i+1];
strcpy(nome, n);
}
char* Person::getName()const{
return nome;
}
This function work correctly but if I define:
char name[20];
I cannot declare the function getName const, if I try to do thsi thing I
receive this error:
impossible to convert char[10] to char*, how can I resolve this error?
Thanks.