+ 3
What is the difference between structure in c and class in C++
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.
+ 2
structs in C are just the collection of public data, and have no C++ class features like methods, constructors, inheritance.
+ 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.
+ 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.
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
0
Bro my question is difference between c structure and c++ class. not c++ structure