I know what constructors are used for, and kinda know what data hiding means.... found absolutely no link among the two (im a dimwit, sedd).... please help?
Asked
Active
Viewed 57 times
-2
-
1Then put that answer down in your homework. What brings you to the conclusion that the two are related in the first place? – Ulrich Eckhardt Aug 14 '19 at 05:58
-
my sensei said so..... and i didn't buy it... XD – Om Nom Aug 14 '19 at 05:59
1 Answers
0
I'd have argued that ctors can be used as a form of RAII. Essentially we can initialise an internal (private) variable via a constructor, and that variable can now be made to be inaccessible outside of the class.
class Foo
{
public:
Foo(int i)
: m_i(i) {} //< only place we init variable
private:
int m_i; //< we cannot access this var
};

robthebloke
- 9,331
- 9
- 12
-
3I don't really see what does RAII has to do with all this. After all, there are no **resources** in your example. – r3mus n0x Aug 14 '19 at 05:49
-
hmm.... but only when we use access specifiers (which were *made* to implement data hiding, r8?) – Om Nom Aug 14 '19 at 06:03