I read other questions here, and there is something that bothers me and hopefully this can be explained. I am sure it is simple, but it alludes to me.
So, in C ++, we have private variables that are only viewable in the class:
class MyClass
{
private:
int i;
};
But we can also have unnamed namespaces:
namespace
{
int i;
}
Both seem private to the class, but in the second case, you cannot see that they exist from the header file. From reading other questions, it seems that the functions are different since you cannot pass class objects to them? But I'm not sure what the difference is here for variables.
Is there a flaw for the second method, which means that you should still use private variables?
source
share