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,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"]
)

View File

@@ -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;
}

View 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;
};

View File

@@ -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;
}