Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
229 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
  • 3
  • 3
7 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 86

Accepted Solution

by:
jkr earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

926 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