Solved

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

Posted on 2015-01-23
7
218 Views
Last Modified: 2015-01-23
Can we say that a structure is a class? What is the difference between class and structure?
0
Comment
Question by:Nusrat Nuriyev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 500 total points
ID: 40567469
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
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 40567471
not usefully

as it would have any methods, so would be inaccessible

are these home/course work questions
0
 

Author Comment

by:Nusrat Nuriyev
ID: 40567563
>>> 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 40567572
>>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
 

Author Closing Comment

by:Nusrat Nuriyev
ID: 40567583
So, struct and class in C++ are almost identical. Fantastico! :)
0
 

Author Comment

by:Nusrat Nuriyev
ID: 40567586
BTW, you have answered to the 11-th question:
11. Can we use  public and private in structures? :)
0
 
LVL 86

Expert Comment

by:jkr
ID: 40567602
Haven't even seen it :-D
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C++ get user from AD  (VS6) 7 95
Focus not getting shifted out of  editbox 2 69
Best book to learn C++ 4 87
Header Errors LNK2019, LNK1120 - Unresolved Externals 4 248
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question