473,382 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

what is difference between structure and class?

structure in c and class in c++
Dec 19 '10 #1
2 2005
Structures can not have functions in them.
Classes have the ADDED functionality of being able to have functions
Dec 19 '10 #2
weaknessforcats
9,208 Expert Mod 8TB
There is only one difference between a struct and a class: The default access for struct members is public whereas the default access for class members is private.

C++ comes from C and in C there is only one way to group data members together: a struct. Therefore, C++ has only structs.

A class is a term used in object technology to represent a group of data members managed by operations.

To make C++ look more object-like a "class" was added to the language. It is implemented as a struct with a private default access.

That means C++ structs can have constructors, destructors, etc.

Try it out. Write a class and get it working with a constructor, destructor and maybe another member function. Once it works, change the "class" keyword to "struct" and rebuild. You will see abolutely nothing happen. The code will work as before.
Dec 19 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: John M. Gabriele | last post by:
I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I...
2
by: akshay4friend | last post by:
Hi, I am creating a structure / class having data type like { DOUBLE x; DOUBLE y; DOUBLE z; }POINT3D; now my data is stored in a file..so i need to create buffer to read
2
by: diadia | last post by:
string s = "hello"; const char *p = s.begin(); cout << p << endl; // print hello s = ""; char *p2= s.begin(); cout << p2 << endl; // print hello why?????
11
by: J Wang | last post by:
dear, I debug the program recently as follows. #include <sys/stat.h> int main(int argc, char *argv) { struct stat buf;
6
by: zacks | last post by:
I recently wrote a VB.NET application using VS2005. I needed to be able to build linked lists in memory of items that were represented by a group of variables. For example, Friend Structure foo...
3
by: John Salerno | last post by:
I've been reading up on them, but I don't quite understand how they differ in practice. I know how each is implemented, and from C# I already know what a static method is. But I won't assume that...
4
by: N.RATNAKAR | last post by:
hai, what is abstract class and abstract method
5
by: bhushanbagul | last post by:
Hi All Please let me know exactly what difference i and g makes in oracle version i.e. when we say oracle 10g or oracle 11i Thanks Bhushan
1
by: kandarp | last post by:
What is partial Class in asp.net ? and How to use it ? . Please Reply me
10
by: Scott Townsend | last post by:
So I need to talk to a devices that expects all of the bits and bytes I sent it to be in specific places (not yet 100% defined). I wanted to create a structure/class with all of the data in it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.