+ 3

What is the difference between structure in c and class in C++

5th Jan 2017, 7:50 AM
sultan Sheikh
sultan Sheikh - avatar
6 Réponses
+ 2
Hi ... we have structure in c++ too ! in a structure unlike a class : 0- struct is a value type and it goes to stack but class is a reference type and it goes to heap. 1- you can't write default constructor 2- if you write a constructor for initializing fields compiler will write a default constructor. 3- if you write a constructor for initializing fields you have to initialize all fields. otherwise you face with error ! 4- you can't initialize your fields when you declare them inside the structure.
5th Jan 2017, 8:56 AM
Amir Goodarzi
Amir Goodarzi - avatar
+ 2
structs in C are just the collection of public data, and have no C++ class features like methods, constructors, inheritance.
5th Jan 2017, 8:58 AM
DFX
DFX - avatar
+ 1
@Sultan Sheikh Thats really not the case Sultan, there are really big differences between the C and C++ structs. What you say is only true for C++ struct.
5th Jan 2017, 9:08 AM
DFX
DFX - avatar
+ 1
@Sultan Sheikh I'm not your bro, pal #kappa Yeah, but I just wanted to say there are really big differences between the structs in C and the Classes in C++. the access modifiers are just one of the easily understandable things of them.
5th Jan 2017, 9:20 AM
DFX
DFX - avatar
0
The main difference is that structure in C the default access is public while in c++ class the default access of data and function member is private
5th Jan 2017, 9:02 AM
sultan Sheikh
sultan Sheikh - avatar
0
Bro my question is difference between c structure and c++ class. not c++ structure
5th Jan 2017, 9:11 AM
sultan Sheikh
sultan Sheikh - avatar