Skip to content

Instantly share code, notes, and snippets.

@koo5
Created July 31, 2017 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koo5/b5118f943630777f9eb014e906d71c96 to your computer and use it in GitHub Desktop.
Save koo5/b5118f943630777f9eb014e906d71c96 to your computer and use it in GitHub Desktop.
#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