同名成员处理
#include <iostream>
using namespace std;
class Base
{
public:
Base()
{
m_A = 100;
}
void func()
{
cout << "Base - func()调用" << endl;
}
void func(int a)
{
cout << "Base - func(int a)调用" << endl;
}
int m_A;
};
class Son :public Base
{
public :
Son()
{
m_A = 200;
}
void func()
{
cout << "Son - func()调用" << endl;
}
int m_A = 200;
};
void test01()
{
Son s;
cout << "Son的m_A= " << s.m_A << endl;
cout << "Base的m_A= " << s.Base::m_A << endl;
}
void test02()
{
Son s;
s.func();
s.Base::func();
}
int main()
{
test01();
test02();
cout << "\n " << endl;
system("pause");
return EXIT_SUCCESS;
}
同名静态成员处理
#include <iostream>
using namespace std;
class Base
{
public:
static int m_A;
static void func()
{
cout << "Base static void func()" << endl;
}
static void func(int a)
{
cout << "Base static void func(int a)" << endl;
}
};
int Base::m_A = 100;
class Son :public Base
{
public :
static int m_A;
static void func()
{
cout << "Son static void func()" << endl;
}
};
int Son::m_A = 200;
void teat01()
{
cout << "通过对象访问 :" << endl;
Son s;
cout << "Son下的m_A=" << s.m_A << endl;
cout << "Base下的m_A=" << s.Base::m_A << endl;
cout << "通过类名访问 :" << endl;
cout << "Son下的m_A=" << Son::m_A << endl;
cout << "Base下的m_A=" << Son::Base::m_A << endl;
}
void test02()
{
Son s;
s.func();
s.Base::func();
Son::func();
Son::Base ::func();
Son::Base ::func(100);
}
int main()
{
teat01();
test02();
system("pause");
return 0;
}
|