Skip to content

Instantly share code, notes, and snippets.

@koo5 koo5/x.cpp
Created Jul 31, 2017

Embed
What would you like to do?
#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
You can’t perform that action at this time.