I wrote the below code in order to explain my issue. If I comment the line 11 (with the keyword "using"), the compiler does not compile the file and displays this error: invalid conversion from 'char' to 'const char*'
. It seems to not see the method void action(char)
of the Parent
class in the Son
class.
Why the compiler behave this way? Or have I done something wrong?
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;
}
Son s = Son();
. That just creates a temporary and then calls the copy constructor. Just typeSon s;
– Claybornusing ...
, dothis->action(...)
just like new languages (i.e. type-script, which forces developers to write "this
" to avoid mistakes). – Greyson