Created
July 2, 2012 17:37
-
-
Save 4poc/3034494 to your computer and use it in GitHub Desktop.
random c++ stuff
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
int main(int argc, char **argv) { | |
int num = 42; | |
// marks value the ptr is refering as constant | |
const int *p1 = # | |
// (*p1)++; // illegal | |
p1++; // legal | |
/////////////////////////////////////////////////// | |
// marks the ptr address as constant | |
int * const p2 = # | |
(*p2)++; // legal | |
// p2++; // illegal | |
/////////////////////////////////////////////////// | |
// marks value the ptr is refering as constant | |
// marks the ptr address as constant | |
const int * const p3 = # | |
// (*p3)++; // illegal | |
// p3++; // illegal | |
return 0; | |
} |
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
#include <iostream> | |
class Example { | |
public: | |
int number; | |
Example(int number) : number(number) {} | |
// returns a const reference of the public attribute number | |
operator const int& () const { | |
return number; | |
} | |
}; | |
int main(int argc, char **argv) { | |
Example e(40); | |
int a = 2; | |
int b = e + a; | |
std::cout << b << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment