How does the computer make sure that a member of a structure cannot be accessed without using an object of that structure? Maybe this badly worded, so here is an example: We have this struct:
struct products
{
int a;
int b;
} apples;
This can only be accessed through an object of the structure, which in this case is apples
:
int main ()
{
apples.a = 20; //the member a can be accessed through apples and a would be another variable if accessed through another object, why is that?
return 0;
}
Same goes for classes...
So how does the computer(not sure what is handling this) make sure that products
's members can only be accessed through an object of that struct or class(type)?
Thanks!