By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,828 Members | 2,241 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,828 IT Pros & Developers. It's quick & easy.

What actually does it mean by Objects, Classes and Methods in C++?

P: 1
May 2 '17 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 9,197
You are an OBJECT.
Human is your CLASS
Speaking is your METHOD
Eating is your METHOD

That's all there is to it. Nothing to do with programming.

How you speak and how you eat are not visible. The methods are ENCAPSULATED.

How you are constructed is hidden under your skin. You have DATA HIDING.

Methods you have that others can see are PUBLIC. Methods you have that you do only by yourself are PRIVATE.

These terms have been translated into programming in an effort to make programs more reliable. Programs written with classes, methods, etc. are called OBJECT ORIENTED.

To make this work in C++ you use a struct since C++ comes from C and in C a struct is all you have to encapsulate data. The struct is your class. To make C++ look nifty, they allowed the name class to be used instead. The only difference between a struct and class in C++ is that the struct is public be default whereas the class is private by default.

A C++ object is a variable created using a struct or class.

A C++ method is a function declared inside a struct or class. You specify public or private on these methods. Private methods can only be used by other methods.
May 2 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.