Created
September 15, 2014 05:33
-
-
Save svaksha/28b1561a658b66c0da5e to your computer and use it in GitHub Desktop.
static_cast by zoe
This file contains hidden or 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 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