Skip to content

Instantly share code, notes, and snippets.

@svaksha
Created September 15, 2014 05:33
Show Gist options
  • Save svaksha/28b1561a658b66c0da5e to your computer and use it in GitHub Desktop.
Save svaksha/28b1561a658b66c0da5e to your computer and use it in GitHub Desktop.
static_cast by zoe
#include <iostream>
class Foo {
public:
Foo() : val(4.2) {}
void a() {
std::cout << "float: " << val << '\n';
}
void b() {
//val stays an float, but the result of static_cast<int>(value) is
//it's value as an int
std::cout << "as a int:" << static_cast<int>(val) << '\n';
}
private:
float val;
};
int main() {
Foo f;
f.b();
f.a();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment