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,29 @@
# please run `bazel run basic_content/struct:ext_struct_func`
# please run `bazel run basic_content/struct:struct_func_func`
# please run `bazel run basic_content/struct:struct_func`
# please run `bazel run basic_content/struct:struct_func_cpp`
load("@rules_cc//cc:defs.bzl", "cc_binary")
cc_binary(
name = "ext_struct_func",
srcs = ["ext_struct_func.cpp"],
copts = ["-std=c++11"]
)
cc_binary(
name = "struct_func_func",
srcs = ["struct_func_func.cpp"],
copts = ["-std=c++11"]
)
cc_binary(
name = "struct_func",
srcs = ["struct_func.cpp"],
copts = ["-std=c++11"]
)
cc_binary(
name = "struct_func_cpp",
srcs = ["struct_func.cpp"],
copts = ["-std=c++11"]
)

Binary file not shown.

View File

@@ -1,33 +1,31 @@
#include<iostream>
#include<stdio.h>
#include <iostream>
#include <stdio.h>
using namespace std;
struct Base {
int v1;
// private: //error!
int v3;
public: //显示声明public
int v2;
virtual void print(){
printf("%s\n","Base");
};
Base(){cout<<"Base construct"<<endl;};
virtual ~Base(){cout<<"Base deconstruct"<<endl;};
struct Base {
int v1;
// private: //error!
int v3;
public: // 显示声明public
int v2;
virtual void print() { printf("%s\n", "Base"); };
Base() { cout << "Base construct" << endl; };
virtual ~Base() { cout << "Base deconstruct" << endl; };
};
struct Derived:Base {
struct Derived : Base {
Derived(){cout<<"Derived construct"<<endl;};
virtual ~Derived(){cout<<"Derived deconstruct"<<endl;};
public:
int v2;
void print(){
printf("%s\n","Derived");
};
Derived() { cout << "Derived construct" << endl; };
virtual ~Derived() { cout << "Derived deconstruct" << endl; };
public:
int v2;
void print() { printf("%s\n", "Derived"); };
};
int main() {
Base *b=new Derived();
b->print();
delete b;
return 0;
Base *b = new Derived();
b->print();
delete b;
return 0;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,27 +1,30 @@
#include<stdio.h>
#include <stdio.h>
struct Base { // public
struct Base
{ // public
int v1;
// public: //error
int v2;
//private:
int v3;
//void print(){ // c中不能在结构体中嵌入函数
// printf("%s\n","hello world");
//}; //error!
// public: //error
int v2;
// private:
int v3;
// void print(){ // c中不能在结构体中嵌入函数
// printf("%s\n","hello world");
// }; //error!
};
void Base(){
printf("%s\n","I am Base func");
void Base()
{
printf("%s\n", "I am Base func");
}
//struct Base base1; //ok
//Base base2; //error
// struct Base base1; //ok
// Base base2; //error
int main() {
int main()
{
struct Base base;
base.v1=1;
//base.print();
printf("%d\n",base.v1);
base.v1 = 1;
// base.print();
printf("%d\n", base.v1);
Base();
return 0;
}

View File

@@ -1,25 +1,24 @@
#include<iostream>
#include<stdio.h>
#include <iostream>
#include <stdio.h>
struct Base {
int v1;
// private: //error!
int v3;
public: //显示声明public
int v2;
void print(){
printf("%s\n","hello world");
};
struct Base {
int v1;
// private: //error!
int v3;
public: // 显示声明public
int v2;
void print() { printf("%s\n", "hello world"); };
};
int main() {
struct Base base1; //ok
Base base2; //ok
Base base;
base.v1=1;
base.v3=2;
base.print();
printf("%d\n",base.v1);
printf("%d\n",base.v3);
return 0;
struct Base base1; // ok
Base base2; // ok
Base base;
base.v1 = 1;
base.v3 = 2;
base.print();
printf("%d\n", base.v1);
printf("%d\n", base.v3);
return 0;
}

View File

@@ -1,39 +1,35 @@
#include<iostream>
#include<stdio.h>
#include <iostream>
#include <stdio.h>
struct Base {
int v1;
// private: //error!
int v3;
public: //显示声明public
int v2;
void print(){
printf("%s\n","hello world");
};
struct Base {
int v1;
// private: //error!
int v3;
public: // 显示声明public
int v2;
void print() { printf("%s\n", "hello world"); };
};
typedef struct Base1 {
int v1;
// private: //error!
int v3;
public: //显示声明public
int v2;
void print(){
printf("%s\n","hello world");
};
}B;
void Base(){
printf("%s\n","I am Base func");
}
//void B() {} //error! 符号 "B" 已经被定义为一个 "struct Base1" 的别名
typedef struct Base1 {
int v1;
// private: //error!
int v3;
public: // 显示声明public
int v2;
void print() { printf("%s\n", "hello world"); };
} B;
void Base() { printf("%s\n", "I am Base func"); }
// void B() {} //error! 符号 "B" 已经被定义为一个 "struct Base1" 的别名
int main() {
struct Base base; //ok
//Base base1; // error!
base.v1=1;
base.v3=2;
base.print();
printf("%d\n",base.v1);
printf("%d\n",base.v3);
Base();
return 0;
struct Base base; // ok
// Base base1; // error!
base.v1 = 1;
base.v3 = 2;
base.print();
printf("%d\n", base.v1);
printf("%d\n", base.v3);
Base();
return 0;
}