Skip to content

Commit 9009f3b

Browse files
authored
Update main.cpp
1 parent 4afd3ba commit 9009f3b

File tree

1 file changed

+12
-6
lines changed
  • basic_content/const/class_const/overload_example

1 file changed

+12
-6
lines changed

basic_content/const/class_const/overload_example/main.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22
#include"apple.cpp"
33
using namespace std;
44
const int Apple::apple_number=10;
5-
Apple::Apple(int i)
5+
#include<iostream>
6+
#include"apple.cpp"
7+
using namespace std;
8+
9+
Apple::Apple(int i):apple_number(i)
610
{
711

812
}
9-
int Apple::add(int num){
10-
take(num);
13+
int Apple::add(){
14+
take(1);
15+
return 0;
1116
}
1217
int Apple::add(int num) const{
1318
take(num);
19+
return num;
1420
}
1521
void Apple::take(int num) const
1622
{
@@ -19,14 +25,14 @@ void Apple::take(int num) const
1925
int Apple::getCount() const
2026
{
2127
take(1);
22-
// add(); //error
28+
add(); // error
2329
return apple_number;
2430
}
2531
int main(){
2632
Apple a(2);
2733
cout<<a.getCount()<<endl;
2834
a.add(10);
29-
const Apple b(3);
30-
b.add(100);
35+
// const Apple b(3);
36+
// b.add(); // error
3137
return 0;
3238
}

0 commit comments

Comments
 (0)