+ 22

Can we make Structure in C++ which have Member Function ?

In C it's not possible.

18th Nov 2019, 3:34 AM
ROHIT KANOJIYA
ROHIT KANOJIYA - avatar
15 odpowiedzi
+ 13
Thanks for the Answer to all. This is helpful for me.
18th Nov 2019, 4:54 AM
ROHIT KANOJIYA
ROHIT KANOJIYA - avatar
+ 10
Avinesh c++ structure support many features of class... Except they have default member public... And no support for class templates
18th Nov 2019, 3:48 AM
Saurabh B
Saurabh B - avatar
+ 10
Thanks to all for Answers This is very helpful for me .
19th Nov 2019, 1:13 PM
ROHIT KANOJIYA
ROHIT KANOJIYA - avatar
+ 7
18th Nov 2019, 3:46 AM
Saurabh B
Saurabh B - avatar
+ 7
Yes in C++
19th Nov 2019, 11:30 AM
Sonic
Sonic - avatar
+ 7
Yes in C++ it is possible. But in C, a member cannot be a function. But a function pointer can be a member of a structure in C
19th Nov 2019, 8:28 PM
Vlad
Vlad - avatar
+ 4
Saurabh B I'm sorry I didn't knew that since I don't use it. But thanks for letting me know.
18th Nov 2019, 3:51 AM
Avinesh
Avinesh - avatar
+ 3
In C language structures cannot contain functions, C++ have classes and not structures and yes we can have member function in classes.
18th Nov 2019, 3:41 AM
Avinesh
Avinesh - avatar
+ 3
Shubham u should check stack-overflow.. Link is mentioned above... Just don't give wrong answer
18th Nov 2019, 6:25 AM
Saurabh B
Saurabh B - avatar
+ 3
https://code.sololearn.com/cxH699AB2SVx/?ref=app Check code for those having doubt....
18th Nov 2019, 6:30 AM
Saurabh B
Saurabh B - avatar
+ 1
Yes saurabh, i didn't see word 'c++' i assume to be question is asked for c language. Hey guys i accept my fault.👍
18th Nov 2019, 6:36 AM
Shubham
Shubham - avatar
0
No That's why the concept of class came forth. It just contain member variables.
18th Nov 2019, 5:54 AM
Shubham
Shubham - avatar