Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 15th Aug 2010, 01:43 PM   #1
Warrior Member
 
Join Date: 2010
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Post
C++
Share on: 
fb share twitter share gplus share more share

what is the difference between structure and classes in c++?

harris2107 is offline  
Unread 15th Aug 2010, 01:56 PM   #2
HyperActive Warrior
War Room Member
 
Backlinks Weekend's Avatar
 
Join Date: 2010
Location: Crowded City
Posts: 321
Thanks: 23
Thanked 19 Times in 15 Posts
Default
Re: C++
Share on: 
fb share twitter share gplus share more share

Structure offers you simple way to manage your data. For example, I can call an account is a simple structure with username and password.

A class is an object, a complex and integrated type of structure where you can have member variables, functions, inheritance, etc. For example, I can have a dog class with function bark, etc.

GET RANK FAST OR MAINTAIN YOUR #1 SPOT - Daily Web 2.0 Submission. Insanely Powerful + Rave Reviews + PROOF!
Backlinks Weekend is offline  
Unread 16th Aug 2010, 01:59 AM   #3
Senior Warrior Member
War Room Member
 
ronperkins's Avatar
 
Join Date: 2010
Location: UK
Posts: 83
Thanks: 2
Thanked 10 Times in 10 Posts
Default
Re: C++
Share on: 
fb share twitter share gplus share more share

The structure default access type is public and should typically be used for grouping data.

The class default access type is private and the default mode for inheritance is private. A class should be used for grouping data and methods that operate on that data.

The convention is to use structures when the purpose is to group data, and use classes when we require data abstraction and, perhaps inheritance.

ronperkins is offline  
Unread 17th Aug 2010, 10:35 AM   #4
Warrior Member
 
Join Date: 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: C++
Share on: 
fb share twitter share gplus share more share

Hi,
Structure is a collection of heterogeneous elements.
For example if you have a
int empno;
Char empname[25];
float salary;

just i want to use as one structure
let us c how can i do with the help of struct

Struct emp
{
int empno;
char empname[20];
float salary;
};
struct emp e1,e2,e3;

see now e1,e2 & e3 are struct type.
now e1 will have all three Fields
similarly e2 & e3 will have three fields.

Class: Class is a collection of objects and methods which you can apply on it, rather
you can say it is a collection of similar type of items.
Regards
Kolla Sanjeeva Rao
ksrao is offline  
Unread 18th Aug 2010, 01:41 AM   #5
Mike Hustler
 
mike_hustler's Avatar
 
Join Date: 2010
Location: United States
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
Default
Re: C++
Share on: 
fb share twitter share gplus share more share

structure and classes both are you can say user defined data types. Both of them can have different predefine datatypes. the main difference is that classes have also member functions in it....

mike_hustler is offline  
Unread 20th Aug 2010, 10:29 PM   #6
Warrior Member
 
Join Date: 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: C++
Share on: 
fb share twitter share gplus share more share

Accoring to Zeeshan "C++ structure and C++ class remain same after introducing virtual function or virtual inheritance ." then why we do introduce a keyword class.

I mean if both are doing the same then whu unneceesary ly we have introduce a keyword class. There might be some reason behind the same

pollocktrance is offline  
Unread 25th Aug 2010, 12:06 AM   #7
Warrior Member
 
Join Date: 2010
Location: Los Angeles, CA, 90060
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: C++
Share on: 
fb share twitter share gplus share more share

In structures there is no security of the data but in case of a class there is a security because it binds both member data and member function on which the data acts.

B|L|V|W
vonthomson is offline  
Unread 26th Aug 2010, 06:57 AM   #8
Warrior Member
 
Join Date: 2010
Posts: 26
Thanks: 5
Thanked 5 Times in 5 Posts
Default
Re: C++
Share on: 
fb share twitter share gplus share more share

Structure: Initially (in C) a structure was used to bundle different type of data types together to perform a particular functionality. But C++ extended the structure to contain functions also. The major difference is that all declarations inside a structure are by default public. Class: Class is a successor of Structure. By default all the members inside the class are private. ..
jeniffer90 is offline  
Unread 1st Sep 2010, 07:45 AM   #9
Warrior Member
 
Join Date: 2010
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: C++
Share on: 
fb share twitter share gplus share more share

thanks all for your help..

harris2107 is offline  
Unread 6th Sep 2010, 03:50 AM   #10
Warrior Member
 
Join Date: 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: C++
Share on: 
fb share twitter share gplus share more share

The members of a structure have public visibility by default, and the members of a class have private visibility by default, so because of the private visibility, the class encourages the use of encapsulation, classes support polymorphism, whereas structures does not support polymorphism, structure does not provide data hiding, well class provides data hiding.

Barbaradavid is offline  
Unread 6th Sep 2010, 12:20 PM   #11
Active Warrior
 
Join Date: 2010
Posts: 88
Thanks: 1
Thanked 3 Times in 3 Posts
Default
Re: C++
Share on: 
fb share twitter share gplus share more share

OO you have asked a very basic question.

you can get many answers on internet. Do RND for this
zeeshi570 is offline  
Unread 6th Nov 2010, 02:13 AM   #12
Warrior Member
 
Join Date: 2010
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: C++
Share on: 
fb share twitter share gplus share more share

thanks alot.

harris2107 is offline  
Closed Thread


Bookmarks

Tags
c++


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 02:57 PM.