Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Constant objects are objects that can only call constant functions from a class.
- Here is one example:
- #include <iostream>
- using namespace std;
- class Sally
- {
- public:
- void printCrap(); //Prototyping the function.
- void printCrap2() const; //Prototyping the constant function.
- };
- int main()
- {
- Sally sallyobject; //Creating an object.
- sallyobject.printCrap(); //Calling a function from the class "Sally"
- const Sally constsallyobject; //Creating a const object.
- constsallyobject.printCrap2(); //Calling a const function.
- return 0;
- }
- void Sally::printCrap() //Creating a function to the class "Sally"
- {
- cout << "I am a function!" << endl;
- }
- void Sally::printCrap2() const //Creating a const function.
- {
- cout << "I am a constant function!" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment