the problem of c++ encapsulation

hi all,
I need help on c++ encapsulation
my code to test the encapsulation:
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
class test {
  private:
       void puts(std::string a);
};
void test::puts(std::string a){
   std::cout<<a;
}
int main(void){
 puts("hello ")
};


fanasymatoMacBook:Cpp zhongweidee$ ./a.out 
hello


1. why main function can access "private" puts member function?
2. how to avoid this access happen?
Thanks for your help
Last edited on
You aren't accessing test::puts(), you are accessing the puts() function inside of cstdlib.
thanks! my mistake.
happy new year!
Topic archived. No new replies allowed.