C history question. Struct member functions.

Click For Summary

Discussion Overview

The discussion centers around the differences between "struct" and "class" in C++, particularly focusing on the introduction of member functions in structs and the historical context of these features. Participants explore whether this functionality was present from the beginning of C or introduced later with C++.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • One participant notes that they believed "struct" in C was similar to "record" in Pascal, but found that C++ structs can have member functions like classes.
  • Another participant claims there is no difference between struct and class in C++, except for the default visibility of members being public in structs.
  • A participant expresses uncertainty about the developmental stages of C++ and suggests that class might be an extension of struct.
  • One participant asserts that member functions are a feature exclusive to C++ and have been part of the language since at least the first ISO standard around 1998, possibly earlier.
  • Another participant mentions that while C does not support member functions, C structs can have pointers to functions, which they consider a similar concept.

Areas of Agreement / Disagreement

Participants generally agree that C does not support member functions, but there is uncertainty regarding the historical introduction of this feature in C++. Multiple views on the relationship between structs and classes in C++ remain unresolved.

Contextual Notes

Some participants express uncertainty about the historical context and developmental stages of C++, indicating a lack of definitive information on when member functions were introduced.

uart
Science Advisor
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. :)
 
Technology 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:
Thanks for the info jtball and rcgldr. :)
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
Replies
6
Views
2K
Replies
12
Views
2K
  • · Replies 1 ·
Replies
1
Views
11K
  • · Replies 10 ·
Replies
10
Views
7K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 14 ·
Replies
14
Views
7K
  • · Replies 8 ·
Replies
8
Views
5K