+18

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

In C it's not possible.

15 Answers

New Answer

+10

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

+10

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

+7

https://stackoverflow.com/questions/13125944/function-for-c-struct Yes we can ,for eg. Follow the link above

+7

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

+6

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

+6

A structure creates a data type that can be used to group items of possibly different types into a single type. The 'struct' keyword is used to create a structure. ... Structures in C++ can contain two types of members: Data Memeber: These members are normal C++ variables

+5

Yes in C++

+4

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

+3

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

+3

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

+3

https://code.sololearn.com/cxH699AB2SVx/?ref=app Check code for those having doubt....

+2

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

+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.👍

+1

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

0

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