Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class TestStaticVariables
- {
- // Private member variable:
- static const double static_double_variable;
- public:
- // Constructor:
- TestStaticVariables()
- {
- // Initialization:
- static const double static_double_variable = 20.0;
- cout << static_double_variable;
- }
- // Member Function:
- void test();
- };
- void TestStaticVariables::test()
- {
- //cout << static_double_variable;
- }
- int main(int argc, char* const argv[])
- {
- TestStaticVariables test_instance;
- return 0;
- }
- #include <iostream>
- class Foo {
- static const double _bar;
- public:
- Foo();
- void Bar();
- };
- const double Foo::_bar = 20.0;
- Foo::Foo() {
- std::cout << Foo::_bar << std::endl;
- }
- void Foo::Bar() {
- std::cout << Foo::_bar << std::endl;
- }
- int main( int argc, char *argv[] ) {
- Foo f;
- f.Bar();
- return 0;
- }
- // Initialization:
- static_double_variable = 20.0;
- // Private member variable:
- static const double static_double_variable;
- const double TestStaticVariables::static_double_variable = 20.0;
Add Comment
Please, Sign In to add comment