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
225 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

Technology Partners: 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!

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

626 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