• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

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?
0
Nusrat Nuriyev
Asked:
Nusrat Nuriyev
  • 3
  • 3
2 Solutions
 
jkrCommented:
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
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
jkrCommented:
>>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
 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now