-2

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?

Om Nom
  • 1
  • 3

1 Answers1

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
  • 3
    I 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