Skip to content

Instantly share code, notes, and snippets.

@IniZio
Created September 9, 2016 01:11
Show Gist options
  • Save IniZio/eeccf8dd6601bd80732c51e20efd7c79 to your computer and use it in GitHub Desktop.
Save IniZio/eeccf8dd6601bd80732c51e20efd7c79 to your computer and use it in GitHub Desktop.
class local and global variables
#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