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
207 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 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now