Created
September 9, 2016 01:11
-
-
Save IniZio/eeccf8dd6601bd80732c51e20efd7c79 to your computer and use it in GitHub Desktop.
class local and global variables
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" | |
using namespace std; | |
int weird = 10; | |
// 'weird' gets constructor local | |
class lab | |
{ | |
int weird; | |
public: | |
lab(){ | |
// int weird = 11; | |
this->weird = 12; | |
std::cout << "this gets constructor local: " << weird << std::endl; | |
std::cout << "this gets class local: " << this->weird << std::endl; | |
std::cout << "this gets global: " << ::weird << std::endl << std::endl; | |
} | |
}; | |
// 'weird' gets class local | |
class lap | |
{ | |
int weird; | |
public: | |
lap(){ | |
weird = 14; | |
std::cout << "this gets class local: " << weird << std::endl; | |
std::cout << "this gets global: " << ::weird << std::endl << std::endl; | |
} | |
}; | |
// 'weird' gets global | |
class laj | |
{ | |
public: | |
laj(){ | |
std::cout << "this gets global: " << weird << std::endl << endl; | |
} | |
}; | |
int main(int argc, char const *argv[]) | |
{ | |
lab lab1; | |
// std::cout << weird << std::endl; | |
lap lap1; | |
laj laj1; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment