c++中常函數的應用舉例

#include
using namespace std;
class R
{
public:
R(int r1, int r2) { R1=r1; R2=r2; }
void print();
void print() const;
private:
int R1, R2;
};


void R::print()
{
cout<<R1<<","<<R2<<endl; 
}


void R::print() const
{
cout<<R1<<","<<R2<<endl;
}


int main()
{
R a(1, 2);
a.print();
const R b(11, 22);
b.print();

}

運行結果:

1,2

11,22


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章