english
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
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;
|
||||
};
|
||||
|
BIN
english/basic_content/const/class_const/static_example/main
Executable file
BIN
english/basic_content/const/class_const/static_example/main
Executable file
Binary file not shown.
@@ -0,0 +1,34 @@
|
||||
#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;
|
||||
}
|
Reference in New Issue
Block a user