6. Can we say that a structure is a class? What is the difference between class and structure?

Can we say that a structure is a class? What is the difference between class and structure?
Nusrat NuriyevAsked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
>>Is the any difference between struct in C and struct in C++?

Yes, a big one. In C++, a struct can have constructors, destructors and methods. You can inherit from a C++ struct and you can derive from it. Plus you can control access to structs by adding protected and private members. They are like classes in C++ with the only difference being the default accessibility as I mentioned above.
0
 
jkrConnect With a Mentor Commented:
A structure is a special case of a class. The main difference is that all members of a struct are accessible as 'public' by default, whereas in the case of a class, it's 'private'. See also http://en.wikipedia.org/wiki/C++_classes#Differences_between_struct_and_classes_in_C++ - they also add that this is the only difference, which I forgor to mention ;o)
0
 
LowfatspreadCommented:
not usefully

as it would have any methods, so would be inaccessible

are these home/course work questions
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Nusrat NuriyevAuthor Commented:
>>> not usefully

>>> as it would have any methods, so would be inaccessible

Don't get this.

>>> are these home/course work questions
No, I'm a C programming language teacher, and I want to learn C++ by asking simple questions. Ability to answer to simple questions tells us who is an expert and who is not.

Additional question:
Is the any difference between struct in C and struct in C++?
0
 
Nusrat NuriyevAuthor Commented:
So, struct and class in C++ are almost identical. Fantastico! :)
0
 
Nusrat NuriyevAuthor Commented:
BTW, you have answered to the 11-th question:
11. Can we use  public and private in structures? :)
0
 
jkrCommented:
Haven't even seen it :-D
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.