support bazel complie this project and format code.
This commit is contained in:
16
basic_content/const/class_const/c++11_example/BUILD
Normal file
16
basic_content/const/class_const/c++11_example/BUILD
Normal file
@@ -0,0 +1,16 @@
|
||||
# please run `bazel run basic_content/const/class_const/c++11_example:main`
|
||||
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
|
||||
|
||||
cc_library(
|
||||
name = "apple",
|
||||
srcs = ["apple.cpp"],
|
||||
hdrs = ["apple.h"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "main",
|
||||
srcs = ["main.cpp"],
|
||||
deps = [
|
||||
":apple",
|
||||
],
|
||||
)
|
@@ -1,15 +1,19 @@
|
||||
class Apple
|
||||
{
|
||||
private:
|
||||
int people[100];
|
||||
public:
|
||||
Apple(int i);
|
||||
//使用c++11标准编译
|
||||
static const int apple_number=10;
|
||||
//const int apple_number=10;
|
||||
void take(int num) const;
|
||||
int add(int num);
|
||||
int add(int num) const;
|
||||
int getCount() const;
|
||||
};
|
||||
#include "apple.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
Apple::Apple(int i) {}
|
||||
int Apple::add(int num) {
|
||||
take(num);
|
||||
return 0;
|
||||
}
|
||||
int Apple::add(int num) const {
|
||||
take(num);
|
||||
return 0;
|
||||
}
|
||||
void Apple::take(int num) const { cout << "take func " << num << endl; }
|
||||
int Apple::getCount() const {
|
||||
take(1);
|
||||
// add(); //error
|
||||
return apple_number;
|
||||
}
|
13
basic_content/const/class_const/c++11_example/apple.h
Normal file
13
basic_content/const/class_const/c++11_example/apple.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
class Apple {
|
||||
public:
|
||||
Apple(int i);
|
||||
// 使用c++11标准编译
|
||||
static const int apple_number = 10;
|
||||
// const int apple_number=10;
|
||||
void take(int num) const;
|
||||
int add(int num);
|
||||
int add(int num) const;
|
||||
int getCount() const;
|
||||
};
|
Binary file not shown.
@@ -1,31 +1,11 @@
|
||||
#include<iostream>
|
||||
#include"apple.cpp"
|
||||
#include "apple.h"
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
Apple::Apple(int i)
|
||||
{
|
||||
|
||||
}
|
||||
int Apple::add(int num){
|
||||
take(num);
|
||||
}
|
||||
int Apple::add(int num) const{
|
||||
take(num);
|
||||
}
|
||||
void Apple::take(int num) const
|
||||
{
|
||||
cout<<"take func "<<num<<endl;
|
||||
}
|
||||
int Apple::getCount() const
|
||||
{
|
||||
take(1);
|
||||
// add(); //error
|
||||
return apple_number;
|
||||
}
|
||||
int main(){
|
||||
Apple a(2);
|
||||
cout<<a.getCount()<<endl;
|
||||
a.add(10);
|
||||
const Apple b(3);
|
||||
b.add(100);
|
||||
return 0;
|
||||
int main() {
|
||||
Apple a(2);
|
||||
cout << a.getCount() << endl;
|
||||
a.add(10);
|
||||
const Apple b(3);
|
||||
b.add(100);
|
||||
return 0;
|
||||
}
|
||||
|
16
basic_content/const/class_const/first_example/BUILD
Normal file
16
basic_content/const/class_const/first_example/BUILD
Normal file
@@ -0,0 +1,16 @@
|
||||
# please run `bazel run basic_content/const/class_const/first_example:main`
|
||||
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
|
||||
|
||||
cc_library(
|
||||
name = "apple",
|
||||
srcs = ["apple.cpp"],
|
||||
hdrs = ["apple.h"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "main",
|
||||
srcs = ["main.cpp"],
|
||||
deps = [
|
||||
":apple",
|
||||
],
|
||||
)
|
@@ -1,13 +1,20 @@
|
||||
class Apple
|
||||
{
|
||||
private:
|
||||
int people[100];
|
||||
public:
|
||||
Apple(int i);
|
||||
const int apple_number;
|
||||
void take(int num) const;
|
||||
int add(int num);
|
||||
int add(int num) const;
|
||||
int getCount() const;
|
||||
};
|
||||
#include "apple.h"
|
||||
#include <iostream>
|
||||
|
||||
Apple::Apple(int i) : apple_number(i) {}
|
||||
int Apple::add(int num) {
|
||||
take(num);
|
||||
return 0;
|
||||
}
|
||||
int Apple::add(int num) const {
|
||||
take(num);
|
||||
return 0;
|
||||
}
|
||||
void Apple::take(int num) const {
|
||||
std::cout << "take func " << num << std::endl;
|
||||
}
|
||||
int Apple::getCount() const {
|
||||
take(1);
|
||||
// add(); //error
|
||||
return apple_number;
|
||||
}
|
11
basic_content/const/class_const/first_example/apple.h
Normal file
11
basic_content/const/class_const/first_example/apple.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
class Apple {
|
||||
public:
|
||||
Apple(int i);
|
||||
const int apple_number;
|
||||
void take(int num) const;
|
||||
int add(int num);
|
||||
int add(int num) const;
|
||||
int getCount() const;
|
||||
};
|
@@ -1,32 +1,12 @@
|
||||
#include<iostream>
|
||||
#include"apple.cpp"
|
||||
#include "apple.h"
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
Apple::Apple(int i):apple_number(i)
|
||||
{
|
||||
|
||||
}
|
||||
int Apple::add(int num){
|
||||
take(num);
|
||||
}
|
||||
int Apple::add(int num) const{
|
||||
take(num);
|
||||
}
|
||||
void Apple::take(int num) const
|
||||
{
|
||||
cout<<"take func "<<num<<endl;
|
||||
}
|
||||
int Apple::getCount() const
|
||||
{
|
||||
take(1);
|
||||
// add(); //error
|
||||
return apple_number;
|
||||
}
|
||||
int main(){
|
||||
Apple a(2);
|
||||
cout<<a.getCount()<<endl;
|
||||
a.add(10);
|
||||
const Apple b(3);
|
||||
b.add(100);
|
||||
return 0;
|
||||
int main() {
|
||||
Apple a(2);
|
||||
cout << a.getCount() << endl;
|
||||
a.add(10);
|
||||
const Apple b(3);
|
||||
b.add(100);
|
||||
return 0;
|
||||
}
|
||||
|
18
basic_content/const/class_const/overload_example/BUILD
Normal file
18
basic_content/const/class_const/overload_example/BUILD
Normal file
@@ -0,0 +1,18 @@
|
||||
# please run `bazel run basic_content/const/class_const/overload_example:main`
|
||||
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
|
||||
|
||||
cc_library(
|
||||
name = "apple",
|
||||
srcs = ["apple.cpp"],
|
||||
hdrs = ["apple.h"],
|
||||
)
|
||||
|
||||
# Don't panic if you get compilation errors, this is what this code demonstrates, as expected.
|
||||
cc_binary(
|
||||
name = "main",
|
||||
srcs = ["main.cpp"],
|
||||
deps = [
|
||||
":apple",
|
||||
],
|
||||
copts = ["-std=c++11"]
|
||||
)
|
@@ -1,13 +1,22 @@
|
||||
class Apple
|
||||
{
|
||||
private:
|
||||
int people[100];
|
||||
public:
|
||||
Apple(int i);
|
||||
static const int apple_number;
|
||||
void take(int num) const;
|
||||
int add();
|
||||
int add(int num) const;
|
||||
int getCount() const;
|
||||
};
|
||||
#include "apple.h"
|
||||
#include <iostream>
|
||||
|
||||
int Apple::apple_number = 10;
|
||||
|
||||
Apple::Apple(int i) { apple_number = i; }
|
||||
int Apple::add() {
|
||||
take(1);
|
||||
return 0;
|
||||
}
|
||||
int Apple::add(int num) const {
|
||||
take(num);
|
||||
return num;
|
||||
}
|
||||
void Apple::take(int num) const {
|
||||
std::cout << "take func " << num << std::endl;
|
||||
}
|
||||
int Apple::getCount() const {
|
||||
take(1);
|
||||
add(); // error
|
||||
return apple_number;
|
||||
}
|
11
basic_content/const/class_const/overload_example/apple.h
Normal file
11
basic_content/const/class_const/overload_example/apple.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
class Apple {
|
||||
public:
|
||||
Apple(int i);
|
||||
static int apple_number;
|
||||
void take(int num) const;
|
||||
int add();
|
||||
int add(int num) const;
|
||||
int getCount() const;
|
||||
};
|
Binary file not shown.
@@ -1,38 +1,12 @@
|
||||
#include<iostream>
|
||||
#include"apple.cpp"
|
||||
using namespace std;
|
||||
const int Apple::apple_number=10;
|
||||
#include<iostream>
|
||||
#include"apple.cpp"
|
||||
#include "apple.h"
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
Apple::Apple(int i):apple_number(i)
|
||||
{
|
||||
|
||||
}
|
||||
int Apple::add(){
|
||||
take(1);
|
||||
return 0;
|
||||
}
|
||||
int Apple::add(int num) const{
|
||||
take(num);
|
||||
return num;
|
||||
}
|
||||
void Apple::take(int num) const
|
||||
{
|
||||
cout<<"take func "<<num<<endl;
|
||||
}
|
||||
int Apple::getCount() const
|
||||
{
|
||||
take(1);
|
||||
add(); // error
|
||||
return apple_number;
|
||||
}
|
||||
int main(){
|
||||
Apple a(2);
|
||||
cout<<a.getCount()<<endl;
|
||||
a.add(10);
|
||||
// const Apple b(3);
|
||||
// b.add(); // error
|
||||
return 0;
|
||||
int main() {
|
||||
Apple a(2);
|
||||
cout << a.getCount() << endl;
|
||||
a.add(10);
|
||||
// const Apple b(3);
|
||||
// b.add(); // error
|
||||
return 0;
|
||||
}
|
||||
|
17
basic_content/const/class_const/static_example/BUILD
Normal file
17
basic_content/const/class_const/static_example/BUILD
Normal file
@@ -0,0 +1,17 @@
|
||||
# please run `bazel run basic_content/const/class_const/static_example:main`
|
||||
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
|
||||
|
||||
cc_library(
|
||||
name = "apple",
|
||||
srcs = ["apple.cpp"],
|
||||
hdrs = ["apple.h"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "main",
|
||||
srcs = ["main.cpp"],
|
||||
deps = [
|
||||
":apple",
|
||||
],
|
||||
copts = ["-std=c++11"]
|
||||
)
|
@@ -1,14 +1,22 @@
|
||||
class Apple
|
||||
{
|
||||
private:
|
||||
int people[100];
|
||||
public:
|
||||
Apple(int i);
|
||||
static int ap; //在类实现文件中定义并初始化
|
||||
static const int apple_number;
|
||||
void take(int num) const;
|
||||
int add(int num);
|
||||
int add(int num) const;
|
||||
int getCount() const;
|
||||
};
|
||||
#include "apple.h"
|
||||
#include <iostream>
|
||||
|
||||
const int Apple::apple_number = 10;
|
||||
int Apple::ap = 666;
|
||||
Apple::Apple(int i) {}
|
||||
int Apple::add(int num) {
|
||||
take(num);
|
||||
return 0;
|
||||
}
|
||||
int Apple::add(int num) const {
|
||||
take(num);
|
||||
return 0;
|
||||
}
|
||||
void Apple::take(int num) const {
|
||||
std::cout << "take func " << num << std::endl;
|
||||
}
|
||||
int Apple::getCount() const {
|
||||
take(1);
|
||||
// add(); //error
|
||||
return apple_number;
|
||||
}
|
11
basic_content/const/class_const/static_example/apple.h
Normal file
11
basic_content/const/class_const/static_example/apple.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
class Apple {
|
||||
public:
|
||||
Apple(int i);
|
||||
static int ap; // 在类实现文件中定义并初始化
|
||||
static const int apple_number;
|
||||
void take(int num) const;
|
||||
int add(int num);
|
||||
int add(int num) const;
|
||||
int getCount() const;
|
||||
};
|
Binary file not shown.
@@ -1,34 +1,11 @@
|
||||
#include<iostream>
|
||||
#include"apple.cpp"
|
||||
using namespace std;
|
||||
const int Apple::apple_number=10;
|
||||
int Apple::ap=666;
|
||||
Apple::Apple(int i)
|
||||
{
|
||||
|
||||
}
|
||||
int Apple::add(int num){
|
||||
take(num);
|
||||
}
|
||||
int Apple::add(int num) const{
|
||||
take(num);
|
||||
}
|
||||
void Apple::take(int num) const
|
||||
{
|
||||
cout<<"take func "<<num<<endl;
|
||||
}
|
||||
int Apple::getCount() const
|
||||
{
|
||||
take(1);
|
||||
// add(); //error
|
||||
return apple_number;
|
||||
}
|
||||
int main(){
|
||||
Apple a(2);
|
||||
cout<<a.getCount()<<endl;
|
||||
cout<<a.ap<<endl;
|
||||
a.add(10);
|
||||
const Apple b(3);
|
||||
b.add(100);
|
||||
return 0;
|
||||
#include "apple.h"
|
||||
#include <iostream>
|
||||
int main() {
|
||||
Apple a(2);
|
||||
std::cout << a.getCount() << std::endl;
|
||||
std::cout << a.ap << std::endl;
|
||||
a.add(10);
|
||||
const Apple b(3);
|
||||
b.add(100);
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user