Created
July 31, 2017 18:26
-
-
Save koo5/b5118f943630777f9eb014e906d71c96 to your computer and use it in GitHub Desktop.
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> | |
int a = 1; | |
int f(int i) | |
{ | |
std::cout << "f" << i; | |
return i * 2; | |
} | |
int g(int x = f(a)) | |
{ | |
return x * 10; | |
} | |
void test1(){ | |
a = 2; // changes the value of ::a | |
std::cout << "g:"<< g(); // calls f(2), then calls g() with the result | |
a = 3; // changes the value of ::a | |
std::cout << "g:"<< g(); // calls f(2), then calls g() with the result | |
} | |
struct banana | |
{ | |
int b; | |
static int a; | |
static int f(int i) | |
{ | |
std::cout << "f" << i; | |
return i * 2; | |
} | |
int g(int x = f(banana::a)) // lookup for f finds ::f, lookup for a finds ::a | |
// the value of ::a, which is 1 at this point, is not used | |
{ | |
return x * 10; | |
} | |
void test2(){ | |
std::cout << "g:"<< g(); // calls f(2), then calls g() with the result | |
a *= 3; // changes the value of ::a | |
std::cout << "g:"<< g(); // calls f(2), then calls g() with the result | |
} | |
}; | |
int banana::a = 5; | |
*/ | |
int main(int argc, char **argv) | |
{ | |
(void)argc;(void)argv; | |
test1(); | |
banana().test2(); | |
std::cout << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment