support bazel complie this project and format code.

This commit is contained in:
zhangxing
2023-03-30 00:15:11 +08:00
committed by light-city
parent 1f86192576
commit 3c8a3f259b
641 changed files with 10349 additions and 9523 deletions

View File

@@ -1,35 +1,31 @@
#include <iostream>
#include <iostream>
using namespace std;
class Base
{
public:
inline virtual void who()
{
cout << "I am Base\n";
}
virtual ~Base() {}
class Base {
public:
inline virtual void who() { cout << "I am Base\n"; }
virtual ~Base() {}
};
class Derived : public Base
{
public:
inline void who() // 不写inline时隐式内联
{
cout << "I am Derived\n";
}
class Derived : public Base {
public:
inline void who() // 不写inline时隐式内联
{
cout << "I am Derived\n";
}
};
int main()
{
// 此处的虚函数 who()是通过类Base的具体对象b来调用的编译期间就能确定了所以它可以是内联的但最终是否内联取决于编译器。
Base b;
b.who();
int main() {
// 此处的虚函数
// who()是通过类Base的具体对象b来调用的编译期间就能确定了所以它可以是内联的但最终是否内联取决于编译器。
Base b;
b.who();
// 此处的虚函数是通过指针调用的,呈现多态性,需要在运行时期间才能确定,所以不能为内联。
Base *ptr = new Derived();
ptr->who();
// 此处的虚函数是通过指针调用的,呈现多态性,需要在运行时期间才能确定,所以不能为内联。
Base *ptr = new Derived();
ptr->who();
// 因为Base有虚析构函数virtual ~Base() {}),所以 delete会先调用派生类Derived析构函数再调用基类Base析构函数防止内存泄漏。
delete ptr;
// 因为Base有虚析构函数virtual ~Base() {}),所以 delete
// 时会先调用派生类Derived析构函数再调用基类Base析构函数防止内存泄漏。
delete ptr;
return 0;
}
return 0;
}