can a structure have member function in C++?? if yes than what is the difference in class and structure? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

can a structure have member function in C++?? if yes than what is the difference in class and structure?

13th Sep 2016, 1:18 PM
subodh Kumar
subodh Kumar - avatar
3 Answers
+ 2
in structure the data member are public so it can be unsafe for us but in c++ there are private visibility mode available so the encapsulation concept will fulfil
13th Sep 2016, 1:24 PM
Twinkle Baisane
Twinkle Baisane - avatar
+ 2
yes we can
13th Sep 2016, 1:32 PM
Twinkle Baisane
Twinkle Baisane - avatar
- 1
in structure, members are public by default but we can make it as private
13th Sep 2016, 1:28 PM
subodh Kumar
subodh Kumar - avatar