A
Albright
Code as bellow:
#include <stdio.h>
#include <string.h>
class A
{
public:
void print(char *s)
{
printf("%s\n", s);
}
};
class B : public A
{
public:
void print(int i)
{
printf("%d\n", i);
}
};
int main()
{
B b;
b.print("hello"); //Has complile error here, it indicates that b
invoke B:rint() but not A:rint, I want to know why.
return 0;
}
In this sample, if print(char *s) is defined in class B, it's OK, but
if in A, it's not.
Why these two functions are NOT overloaded between base class and sub
class?
#include <stdio.h>
#include <string.h>
class A
{
public:
void print(char *s)
{
printf("%s\n", s);
}
};
class B : public A
{
public:
void print(int i)
{
printf("%d\n", i);
}
};
int main()
{
B b;
b.print("hello"); //Has complile error here, it indicates that b
invoke B:rint() but not A:rint, I want to know why.
return 0;
}
In this sample, if print(char *s) is defined in class B, it's OK, but
if in A, it's not.
Why these two functions are NOT overloaded between base class and sub
class?