Skip to content

Instantly share code, notes, and snippets.

Created July 27, 2016 15:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
C++ program to implement const objects and const functions :
using namespace std;
class temp{
void fn();
void constantfn() const;
void temp::fn(){
cout<<"Hello, Am an normal function."<<endl;
void temp::constantfn() const{
cout<<"Hi, Am an constant function :P"<<endl;
int main()
// Normal Objects can call both normal and constant functions.
temp x;
// Constant Objects can call only constant functions.
const temp y;
int a=10;
// Constant Pointer...
int* const ptr=&a;
cout<<"The value pointed by the constant pointer is "<<*ptr<<endl;
int b=20;
// Pointer to constant...
const int* ptr2=&b;
cout<<"The constant value pointed by the pointer is "<<*ptr2<<endl;
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment