Ho scritto il seguente codice per spiegare il mio problema. Se commento la riga 11 (con la parola chiave "using"), il compilatore non compila il file e visualizza questo errore: invalid conversion from 'char' to 'const char*'
. Sembra non vedere il metodo void action(char)
della classe Parent
nella classe Son
.Perché dovrei usare la parola chiave "using" per accedere al metodo della mia classe base?
Perché il compilatore si comporta in questo modo? O ho fatto qualcosa di sbagliato?
class Parent
{
public:
virtual void action(const char how){ this->action(&how); }
virtual void action(const char * how) = 0;
};
class Son : public Parent
{
public:
using Parent::action; // Why should i write this line?
void action(const char * how){ printf("Action: %c\n", *how); }
};
int main(int argc, char** argv)
{
Son s = Son();
s.action('a');
return 0;
}
Per favore dimmi: cosa succede se si rimuove const in "const char how"? –
Non è necessario digitare 'Son s = Son();'. Questo crea solo un temporaneo e quindi chiama il costruttore di copie. Basta digitare 'Son s;' –
Otteniamo questa domanda molto: [http://stackoverflow.com/questions/1835988](http://stackoverflow.com/questions/1835988) [http://stackoverflow.com/ questions/411103] (http://stackoverflow.com/questions/411103) [http://stackoverflow.com/questions/1480085](http://stackoverflow.com/questions/1480085) [http: // stackoverflow. it/questions/1799497] (http://stackoverflow.com/questions/1799497) [http://stackoverflow.com/questions/888235](http://stackoverflow.com/questions/888235) [http: // stackoverflow.com/questions/72010](http://stackoverflow.com/questions/72010) –