#include <iostream>
using namespace std;
class A{
public:
A(int ii,int cii):i(ii),ci(ci){
}
void f(){ //void f(A* this)
cout<<"f()"<<endl;
}
void f() const{ //void f(const A*this)
cout<<"f() const"<<endl;
//i++; //wrong!
}
private:
int i;
const int ci; //ci has to be initialized whether or
//or not the object is a const
};
int main(){
const A a(3,5); //a is const,i has to be initialized
a.f();
int x=10;
const int y=x;
const int z=10;
int c[z];
return 0;
}
const
最新推荐文章于 2024-06-20 10:49:56 发布