mirror of
https://github.com/Light-City/CPlusPlusThings.git
synced 2026-02-03 18:43:52 +08:00
support bazel complie this project and format code.
This commit is contained in:
@@ -1,27 +1,28 @@
|
||||
/**
|
||||
* @file abstract.cpp
|
||||
* @brief 抽象类中:在成员函数内可以调用纯虚函数,在构造函数/析构函数内部不能使用纯虚函数
|
||||
* @brief
|
||||
* 抽象类中:在成员函数内可以调用纯虚函数,在构造函数/析构函数内部不能使用纯虚函数
|
||||
* 如果一个类从抽象类派生而来,它必须实现了基类中的所有纯虚函数,才能成为非抽象类
|
||||
* @author 光城
|
||||
* @version v1
|
||||
* @date 2019-07-20
|
||||
*/
|
||||
|
||||
#include<iostream>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
class A {
|
||||
public:
|
||||
virtual void f() = 0; // 纯虚函数
|
||||
void g(){ this->f(); }
|
||||
A(){}
|
||||
virtual void f() = 0; // 纯虚函数
|
||||
void g() { this->f(); }
|
||||
A() {}
|
||||
};
|
||||
class B:public A{
|
||||
class B : public A {
|
||||
public:
|
||||
void f(){ cout<<"B:f()"<<endl;}
|
||||
void f() { cout << "B:f()" << endl; }
|
||||
};
|
||||
int main(){
|
||||
B b;
|
||||
b.g();
|
||||
return 0;
|
||||
int main() {
|
||||
B b;
|
||||
b.g();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user