Can we make Structure in C++ which have Member Function ? | SoloLearn: Learn to code for FREE!


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

In C it's not possible.

11/18/2019 3:34:55 AM


15 Answers

New Answer


Thanks for the Answer to all. This is helpful for me.


Avinesh c++ structure support many features of class... Except they have default member public... And no support for class templates


Thanks to all for Answers This is very helpful for me .


It is possible in C, the catch is you have to use function pointers

+7 Yes we can ,for eg. Follow the link above


Yes in C++


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


Saurabh B I'm sorry I didn't knew that since I don't use it. But thanks for letting me know.


In C language structures cannot contain functions, C++ have classes and not structures and yes we can have member function in classes.


Shubham u should check stack-overflow.. Link is mentioned above... Just don't give wrong answer

+3 Check code for those having doubt....


Yes saurabh, i didn't see word 'c++' i assume to be question is asked for c language. Hey guys i accept my fault.👍


The answer of What you are asking is : Class. And this is in C++(Object Oriented Programming).


No That's why the concept of class came forth. It just contain member variables.