D
Daniel Barna
Hi
I am a bit confused. I thought always that if a class inherits from
another (public), then all of its base class's public member function
are also visible in this class - even if it declares a function with
the same name, but different parameters.
However, when I try to compile the example below, the compiler claims
that there is no appropriate function:
invalid conversion from 'int' to 'const char *'
initializing argument 1 of 'void B:ush_back(const char *)'
However, if I don't declare a 'push_back' function inside 'class B',
then everything works fine. Should the compiler in this case not
resolve the
'push_back' function (based on its argument type: int) to
A:ush_back(int) ?
Thank you
DAniel
-----
class A
{ public:
void push_back(int) {}
};
class B : public A
{ public:
void push_back(const char *) {}
};
int main()
{
B b;
b.push_back(1);
return 0;
}
I am a bit confused. I thought always that if a class inherits from
another (public), then all of its base class's public member function
are also visible in this class - even if it declares a function with
the same name, but different parameters.
However, when I try to compile the example below, the compiler claims
that there is no appropriate function:
invalid conversion from 'int' to 'const char *'
initializing argument 1 of 'void B:ush_back(const char *)'
However, if I don't declare a 'push_back' function inside 'class B',
then everything works fine. Should the compiler in this case not
resolve the
'push_back' function (based on its argument type: int) to
A:ush_back(int) ?
Thank you
DAniel
-----
class A
{ public:
void push_back(int) {}
};
class B : public A
{ public:
void push_back(const char *) {}
};
int main()
{
B b;
b.push_back(1);
return 0;
}