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

Posted on 2015-01-23
Last Modified: 2015-01-23
Can we say that a structure is a class? What is the difference between class and structure?
Question by:Nusrat Nuriyev
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
LVL 86

Assisted Solution

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 - they also add that this is the only difference, which I forgor to mention ;o)
LVL 50

Expert Comment

ID: 40567471
not usefully

as it would have any methods, so would be inaccessible

are these home/course work questions

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++?
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!

LVL 86

Accepted Solution

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.

Author Closing Comment

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

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? :)
LVL 86

Expert Comment

ID: 40567602
Haven't even seen it :-D

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

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…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

752 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