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 7529ae3a55
636 changed files with 10025 additions and 9387 deletions

View File

@@ -1,6 +1,6 @@
/**
* @file virtual_inline.cpp
* @brief 通常类成员函数都会被编译器考虑是否进行内联。
* @brief 通常类成员函数都会被编译器考虑是否进行内联。
* 但通过基类指针或者引用调用的虚函数必定不能被内联。
* 当然,实体对象调用虚函数或者静态调用时可以被内联,虚析构函数的静态调用也一定会被内联展开。
* @author 光城
@@ -8,37 +8,28 @@
* @date 2019-07-24
*/
#include <iostream>
using namespace std;
class Base
{
public:
virtual void who()
{
cout << "I am Base\n";
}
};
class Derived: public Base
{
public:
void who()
{
cout << "I am Derived\n";
}
};
#include <iostream>
using namespace std;
class Base {
public:
virtual void who() { cout << "I am Base\n"; }
};
class Derived : public Base {
public:
void who() { cout << "I am Derived\n"; }
};
int main()
{
// note here virtual function who() is called through
// object of the class (it will be resolved at compile
// time) so it can be inlined.
Base b;
b.who();
int main() {
// note here virtual function who() is called through
// object of the class (it will be resolved at compile
// time) so it can be inlined.
Base b;
b.who();
// Here virtual function is called through pointer,
// so it cannot be inlined
Base *ptr = new Derived();
ptr->who();
// Here virtual function is called through pointer,
// so it cannot be inlined
Base *ptr = new Derived();
ptr->who();
return 0;
}
return 0;
}