It occurs to me that, I should reword my question. Is there any difference between these two implementation when the compiler does its optimization?
Sorry about the confusion. I do understand the importance of encapsulation and that is not what i am asking about.
class A
{
public:
int get_data{return m_data;}
private:
int m_data;
}
class B
{
public:
int get_data{return m_data;}
private:
volatile int m_data;
}