Update main.cpp

This commit is contained in:
Francis 2022-04-10 18:06:34 +08:00 committed by GitHub
parent 4afd3bab38
commit 9009f3b480
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,15 +2,21 @@
#include"apple.cpp" #include"apple.cpp"
using namespace std; using namespace std;
const int Apple::apple_number=10; const int Apple::apple_number=10;
Apple::Apple(int i) #include<iostream>
#include"apple.cpp"
using namespace std;
Apple::Apple(int i):apple_number(i)
{ {
} }
int Apple::add(int num){ int Apple::add(){
take(num); take(1);
return 0;
} }
int Apple::add(int num) const{ int Apple::add(int num) const{
take(num); take(num);
return num;
} }
void Apple::take(int num) const void Apple::take(int num) const
{ {
@ -19,14 +25,14 @@ void Apple::take(int num) const
int Apple::getCount() const int Apple::getCount() const
{ {
take(1); take(1);
// add(); //error add(); // error
return apple_number; return apple_number;
} }
int main(){ int main(){
Apple a(2); Apple a(2);
cout<<a.getCount()<<endl; cout<<a.getCount()<<endl;
a.add(10); a.add(10);
const Apple b(3); // const Apple b(3);
b.add(100); // b.add(); // error
return 0; return 0;
} }