the inheritance and the scoping

What are the potential problems that you can think of (AND how would you fix it?) with the following code:

class Host { int x;
class Nested_One extends Some_Other_Class {
void add_one() {
x++;
}
}
}
any help?
x is not a member of the calss Nested_One, hence you cannot access x directly. You need to pass an instance of Host in order to access x.


Please use code tags: [code]Your code[/code]
Read this: http://www.cplusplus.com/articles/z13hAqkS/
but I thought x is defined in a global scope.. no?
No. If you want to make the variable global use static:

http://en.cppreference.com/w/cpp/language/static

Note that if you declare a variable static inside a class you need to define it outside:
1
2
3
4
5
class Host { static int x;
...
}

int Host::x = 0;
Topic archived. No new replies allowed.