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

@@ -0,0 +1,8 @@
# please run `bazel run basic_content/virtual/set1:emp`
load("@rules_cc//cc:defs.bzl", "cc_binary")
cc_binary(
name = "emp",
srcs = ["emp.cpp"],
copts = ["-std=c++11"]
)

Binary file not shown.

View File

@@ -1,52 +1,40 @@
#include<iostream>
#include <iostream>
using namespace std;
class Employee {
public:
virtual void raiseSalary() { cout << 0 << endl; }
class Employee
{
public:
virtual void raiseSalary()
{
cout<<0<<endl;
}
virtual void promote() { /* common promote code */
}
};
virtual void promote()
{ /* common promote code */ }
};
class Manager : public Employee {
virtual void raiseSalary() { cout << 100 << endl; }
class Manager: public Employee {
virtual void raiseSalary()
{
cout<<100<<endl;
}
virtual void promote() { /* Manager specific promote */
}
};
class Engineer : public Employee {
virtual void raiseSalary() { cout << 200 << endl; }
virtual void promote()
{ /* Manager specific promote */ }
};
class Engineer: public Employee {
virtual void raiseSalary()
{
cout<<200<<endl;
}
virtual void promote() { /* Manager specific promote */
}
};
virtual void promote()
{ /* Manager specific promote */ }
};
// Similarly, there may be other types of employees
// We need a very simple function to increment salary of all employees
// Note that emp[] is an array of pointers and actual pointed objects can
// be any type of employees. This function should ideally be in a class
// like Organization, we have made it global to keep things simple
void globalRaiseSalary(Employee *emp[], int n)
{
for (int i = 0; i < n; i++)
emp[i]->raiseSalary(); // Polymorphic Call: Calls raiseSalary()
// according to the actual object, not
// according to the type of pointer
}
int main(){
Employee *emp[]={new Manager(),new Engineer};
globalRaiseSalary(emp,2);
return 0;
// Similarly, there may be other types of employees
// We need a very simple function to increment salary of all employees
// Note that emp[] is an array of pointers and actual pointed objects can
// be any type of employees. This function should ideally be in a class
// like Organization, we have made it global to keep things simple
void globalRaiseSalary(Employee *emp[], int n) {
for (int i = 0; i < n; i++)
emp[i]->raiseSalary(); // Polymorphic Call: Calls raiseSalary()
// according to the actual object, not
// according to the type of pointer
}
int main() {
Employee *emp[] = {new Manager(), new Engineer};
globalRaiseSalary(emp, 2);
return 0;
}