What is the difference between structures and classes in C++?

There is only one difference ,in classes the members are private by default whereas it is not so in structures.

Showing Answers 1 - 20 of 20 Answers

difference between structures and clas...

Ans:

Structs are value-type variables and are thus saved on the stack, additional overhead but faster retrieval.  Another difference is that structs cannot inherit. 

  Was this answer useful?  Yes

Dinesh Taparia

  • Apr 2nd, 2007
 

U can inherit structure. And the default inheritence is public whereas in class the default inheritence is private

  Was this answer useful?  Yes

heyjoe

  • May 21st, 2007
 

There is only one difference between struct & class in 'C++'..  All the variables/functions in struct are 'public' and in class they are 'private' by default.  This is a very common misconception even among experienced Software engineers.

  Was this answer useful?  Yes

MAYUR BHAYANI

  • Aug 20th, 2007
 

There is not just a one difference. Differences are many like
The structure are uses stack and class uses heap memory.
The structure cannot use pointers while class can.
The strucure may not have private.
You can not define object of structure while you can define object of class.
Class is a blue print, while structure is actual data.

Mayur Bhayani

  Was this answer useful?  Yes

Amit Gupta

  • Oct 26th, 2007
 

class does not occupy any memory until we are not going to define any object for that class.
In other way class are the blue print and object are the real time entity or instance of the class which is occupying the memory.

Class are other features like abstraction , encapsulation , polymorphism which are not implemented by structure.

  Was this answer useful?  Yes

berezleon

  • Dec 1st, 2007
 

Amid, you are talking about "C" structure that knows nothing about classes etc. The only difference between C++ class and struct is default access specifier (private and public respectively)

  Was this answer useful?  Yes

sripudi

  • Jan 5th, 2009
 

There are a lot of differences between Structure & Class in C.
But in C++ the only difference is the members structure are by default public where as class members are by default private.
Using C++ structure we can do the OOPS concepts like inheritance

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions