C++ 子类调用父类的方法,静态方法的调用
#include <iostream>
class A
{
public:
A();
~ A();
virtualvoid say()
{
std::cout << "Hello this is class A!\n";
}
static void test()
{
std::cout << "Hello this is class A test function..!\n";
}
private:
};
A:: A()
{
}
A::~ A()
{
}
class B: public A
{
public:
B();
~ B();
void say()
{
A::say();
std::cout << "Hello this is class B..!\n";
}
private:
};
B:: B()
{
}
B::~ B()
{
}
int main()
{
A::test();
B b;
b.say();
std::cout << "Hello World!\n";
}
输出的结果:
#include <iostream>
class A{public: A();~ A();virtualvoid say(){std::cout << "Hello this is class A!\n";}static void test(){std::cout << "Hello this is class A test function..!\n";}private:
};
A:: A(){}
A::~ A(){}
class B: public A { public: B(); ~ B(); void say() { A::say(); std::cout << "Hello this is class B..!\n"; } private:
};
B:: B() { }
B::~ B() { }
int main(){A::test();B b;b.say(); std::cout << "Hello World!\n";}