C history question. Struct member functions.

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
5 replies · 4K views
Messages
2,797
Reaction score
21
Old Pascal/Delphi programmer here with a question about c. I can kinda make my way around in c/c++ but I'm no expert.

I always thought the "struct" data type in c was just a mixed data type similar to "record" in Pascal. Now I find that "struct" in c++ can have member functions and basically do everything that "class" can do.

I was just wondering when this functionality entered or if it was always there? Was it something that was added in c++ (so not in c) or was it a feature added at some other time (or even was it there from the beginning of c)?

Thanks. :)
 
Physics news on Phys.org
Basically, there is no difference between structure and Class in C++. The only difference is that the default visibility of members in structure is public.

I think, once the concept of class was used in C++, they realized class was just an extension to structure, and they felt they should ... Ok, leave out, I am just fantasizing. :). I really don't know anything about the developmental stages of C++. Sorry.
 
I_am_learning said:
Basically, there is no difference between structure and Class in C++. The only difference is that the default visibility of members in structure is public.

I think, once the concept of class was used in C++, they realized class was just an extension to structure, and they felt they should ... Ok, leave out, I am just fantasizing. :). I really don't know anything about the developmental stages of C++. Sorry.

Yeah I've recently been refreshing my knowledge of c++ and that's when I notice this. "Stuct" seems to be pretty much the same as "class" except for differences in the defaults for public/private. I understand that, I'm just wondering when this functionality entered the language. Was it something added to c++ or did it come earlier/later than that?
 
C has no notion of member functions. Member functions in structs are purely a C++ thing, and have been part of C++ since at least the first ISO standard around 1998, probably earlier.

(as far as I know)

I didn't keep my old version of Bjarne Stroustrup's The C++ Programming Language from the early 1990s, which would probably say what the situation was at that time.
 
As mentioned, C doesn't support member functions, but C structs can have pointers to functions, which is similar.
 
Last edited: