Inforrmation member funtion in C

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sridhard2406
    New Member
    • Dec 2007
    • 52

    Inforrmation member funtion in C

    Hi All,
    Could you please anybody tell me, why c structer is not allowing funtion as the one of the member as c++ allows.

    Thanks,
    Sridhar.D
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Because that is one of the major differencesbetw een C and C++.

    C supports data structures, that is user defined types consisting of 1 or more data members.

    C++ supports objects, that is user defined types that have 0 or more data members and 2 or more function members. I believe every object must have a constructor of some sort, an assignment operator, if these are not explicitly provided the compiler provides default implementations for you.

    Your question is a bit like asking why does a motorcycle have 2 wheels when a car has 4? It is a defining feature of the thing in question.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      However, you can have a function pointer as a struct member.

      All yuo need do is assign the address of your function to the function pointer in the struct and you can do most of what C++ does.

      Comment

      • sridhard2406
        New Member
        • Dec 2007
        • 52

        #4
        Thanks for your reply

        Comment

        Working...