Skip to content

Instantly share code, notes, and snippets.

@4poc
Created July 2, 2012 17:37
Show Gist options
  • Save 4poc/3034494 to your computer and use it in GitHub Desktop.
Save 4poc/3034494 to your computer and use it in GitHub Desktop.
random c++ stuff
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;
}
#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