473,378 Members | 1,401 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,378 software developers and data experts.

main difference between STRUCT AND CLASS

11
Hi,

I want to ask what is basically main difference between struct and class??
when we should use struct instead of class.??

Mack.
Mar 6 '07 #1
5 1931
DeMan
1,806 1GB
As a general rule (and I'm sure I'll be corrected, because I believe you can do other things), a structure is used to store items of data, a method/function is used to do things.....
so a structure might be able to STORE x and x^2, but a method would take x and CALCULATE x^2

Hope that makes some sense....
Mar 6 '07 #2
chella
51
Hi,

I want to ask what is basically main difference between struct and class??
when we should use struct instead of class.??

Mack.

Hi Mack,
In Structure : The data members of a structure are not private. It can be accessed by any function in the program.

In class : The data members of a class are secure since only the member functions of that class can access it. By usin class the data is more secure.

Regards,
Chella
Mar 6 '07 #3
DeMan
1,806 1GB
And that will teach me for not reading the question properly (again).......
Mar 6 '07 #4
Mack
11
Thanks friends
Mar 6 '07 #5
r035198x
13,262 8TB
Hi Mack,
In Structure : The data members of a structure are not private. It can be accessed by any function in the program.

In class : The data members of a class are secure since only the member functions of that class can access it. By usin class the data is more secure.

Regards,
Chella
Yes classes encapsulates data better an provides data security. They also allow for inheritance and polymorphism making it possible to write extensible and more efficient solutions to problems.
Mar 6 '07 #6

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

Similar topics

45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
11
by: Shea Martin | last post by:
I have been programming in C++ for over 4 years. I *think* I knew that a struct could have a constructor but I decided to dig into it a little more today, and found that there is very little...
22
by: Ook | last post by:
We have had a discussion on the differences between a class and a structure, and no one is in agreement. As I understand it, a structure defaults to public, a class defaults to private. There are...
6
by: XiongBin | last post by:
anybody who tell me: what is the difference between "struct" and "class"? :-)
6
by: nick | last post by:
I have tried finding an answer to this, but most people just explain classes as a more modular way to program. It seems to me that (forgetting OO programming which I don't quite understand) the...
5
by: Chris | last post by:
Hi, I don't get the difference between a struct and a class ! ok, I know that a struct is a value type, the other a reference type, I understand the technical differences between both, but...
5
by: Martin Jørgensen | last post by:
Hi, Consider this code: --- beginning of code --- #include <iostream> using namespace std; class Child{ public:
7
by: raghunandan_1081 | last post by:
Hi guys, can you please tell me what is the Difference between c structure and c++ structure
6
by: fcvcnet | last post by:
Hi, I read the book C++ Primer, Fourth Edition By Stanley B. Lippman, Jos¨¦e Lajoie, Barbara E. Moo "If we define a class using the class keyword, then any members defined before the first...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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.