[Cpp]
/*
* Copyright and version Declaration of the program
* Copyright (c) 2013, a student from the computer College of Yantai University
* All rightsreserved.
* File name: object. cpp
* Author: Yang shaoning
* Completion date: January 1, April 5, 2013
* Version: v1.0
* Input Description: None
* Problem description: common functions.
* Program output: score.
*/
(1)
# Include <iostream>
# Include <stdlib. h>
Using namespace std;
Class C
{Private:
Int x;
Public:
C (int x) {this-> x = x ;}
Int getX () const {return x ;}
};
Int main ()
{Const C c (5 );
Cout <c. getX ();
Return 0;
}
(2)
# Include <iostream>
# Include <stdlib. h>
Using namespace std;
Class C
{Private:
Int x;
Public:
C (int x) {this-> x = x ;}
Int getX () {return x ;}
};
Int main ()
{C c (5 );
Cout <c. getX ();
Return 0;
}
/*
* Copyright and version Declaration of the program
* Copyright (c) 2013, a student from the computer College of Yantai University
* All rightsreserved.
* File name: object. cpp
* Author: Yang shaoning
* Completion date: January 1, April 5, 2013
* Version: v1.0
* Input Description: None
* Problem description: common functions.
* Program output: score.
*/
(1)
# Include <iostream>
# Include <stdlib. h>
Using namespace std;
Class C
{Private:
Int x;
Public:
C (int x) {this-> x = x ;}
Int getX () const {return x ;}
};
Int main ()
{Const C c (5 );
Cout <c. getX ();
Return 0;
}
(2)
# Include <iostream>
# Include <stdlib. h>
Using namespace std;
Class C
{Private:
Int x;
Public:
C (int x) {this-> x = x ;}
Int getX () {return x ;}
};
Int main ()
{C c (5 );
Cout <c. getX ();
Return 0;
}
Result:
Feel: Because the get () function only outputs but does not modify it, it is better to have a const !!