1// thing.cpp
2
3namespace thing
4{
5 namespace // anonymous namespace
6 {
7 int x = 1;
8 int y = 2;
9
10 int sum(int a, int b)
11 {
12 return a + b;
13 }
14 }
15
16 int getX()
17 {
18 return x;
19 }
20
21 int getSum()
22 {
23 return sum(x, y);
24 }
25};
26
1#include <cstdio>
2#include "thing.hpp"
3
4int main(int argc, char **argv)
5{
6 printf("%d\n", thing::getX()); // OK
7 printf("%d\n", thing::getSum()); // OK
8 printf("%d\n", thing::sum(1, 2)); // error: ‘sum‘ is not a member of ‘thing’
9 printf("%d\n", thing::y); // error: ‘y‘ is not a member of ‘thing’
10}
11