class A
{
public:
void fun(int a, int b)
{
std::cout << a + b << std::endl;
}
};
class B :public A
{
public:
void fun(int a)
{
std::cout << a << std::endl;
}
};
class C
{
public:
C()
{
}
~C()
{
}
void func(int a)
{
std::cout << "input:" << a << std::endl;
m_a = a;
std::cout << "set:" << m_a << std::endl;
}
virtual void func1(int a)
{
std::cout << "input:" << a << std::endl;
m_a = a;
std::cout << "set:" << m_a << std::endl;
}
private:
int m_a;
};
void test001(void)
{
A *pA = new B;
pA->fun(1);
B b;
b.fun(1, 3);
delete pA;
return;
}
void test002()
{
C*pC = nullptr;
pC->func(1);
return;
}
void test003()
{
C*pC = nullptr;
pC->func1(1);
return;
}
以上代码中存在的问题以及原因。