Last active
February 6, 2020 21:01
-
-
Save rudradesai200/0249555f5d80a3c0aa4d305214c1871c to your computer and use it in GitHub Desktop.
Code used in my first medium article. Check it out here https://medium.com/@rudra.desai200/how-to-use-const-keyword-in-c-b65ee42cf09
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dummy { | |
private: | |
int X = 0; | |
public: | |
//this function will give an error if | |
//object declared is of constant type | |
int getX() { return X; } | |
//this function will work fine as | |
//we have declared it const. | |
void printX() const { std::cout<<X<<std::endl; } | |
}; | |
int main(){ | |
const Dummy d; | |
// d.getX(); //it will return a compilation error if uncommented | |
d.printX(); //it will work just fine | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment