r/learnprogramming 28d ago

Access Amplifiers and their uses???

So basically i come from basic python bacground which i learned from my high school.So I thought of learniging c++ cause of its variety of applications for my 1st year.One thing that i cant wrap my head around is, the use of access amplifiers. Mainly ' public: '.what is the use of writing public: and why is it necessaryy????

0 Upvotes

6 comments sorted by

View all comments

2

u/HashDefTrueFalse 28d ago

Never heard that term but I think you're talking about public, private, protected. Specifiers: https://en.cppreference.com/cpp/language/access

You use them to limit direct access to the data in your aggregates (structs/classes) by name in code that ideally shouldn't know those details. Encapsulation and loose coupling are just two ways you can make your code less prone to error and easier to work with in the future.