Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #11091
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.programming |
| Subject | Re: when to use a struct(ure) or a class? |
| Date | 2020-07-25 00:52 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <rffon0$mnt$1@dont-email.me> (permalink) |
| References | <f53949d7-80a0-44ec-a157-ff7a82f31bb8o@googlegroups.com> <rffmnv$djq$1@dont-email.me> <c093df03-f588-40a7-845e-4e8846a1eba5o@googlegroups.com> |
On 25/07/2020 00:29, G G wrote: > On Friday, July 24, 2020 at 6:18:42 PM UTC-4, David Brown wrote: >> On 25/07/2020 00:06, G G wrote: >>> when do you choose a structure over a class when the >>> language supports functions inside of the struct(ure) >>> definitions? >>> >> >> Are you thinking specifically of C++, which has both "struct" and >> "class" ? (Maybe you have other languages in mind, but that's the only >> one I know that fits your question.) C++ as a language doesn't care >> about "class" vs. "struct" - the only difference is the default >> visibility of the members (private vs. public). So it is a matter of >> programmer style. But a very common distinction is that types where the >> data members have an invariant - some relationship between them that >> should be kept - should be a "class" with private data members accessed >> via methods (or sometimes friend functions). A type where the data >> members are basically independent and can reasonably be accessed >> directly, would be a "struct" even if there are also member functions. >> If there are virtual functions, or inheritance involved, you almost >> certainly would call it a "class". >> >> So a simple x, y point structure would be a "struct", while something >> holding an array of data along with a current length would be a "class". > > the language i'm thinking about as swift. > OK. I don't know Swift at all, so I can't say if people use a similar convention there. It's nice to see real posts and real questions in this newsgroup, but I suspect that you'll get more concrete answers in a dedicated Swift newsgroup or Apple programming group (I don't think anyone else uses Swift, do they?).
Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
when to use a struct(ure) or a class? G G <gdotone@gmail.com> - 2020-07-24 15:06 -0700
Re: when to use a struct(ure) or a class? David Brown <david.brown@hesbynett.no> - 2020-07-25 00:18 +0200
Re: when to use a struct(ure) or a class? G G <gdotone@gmail.com> - 2020-07-24 15:29 -0700
Re: when to use a struct(ure) or a class? David Brown <david.brown@hesbynett.no> - 2020-07-25 00:52 +0200
Re: when to use a struct(ure) or a class? Öö Tiib <ootiib@hot.ee> - 2020-07-25 15:31 -0700
Re: when to use a struct(ure) or a class? Julio Di Egidio <julio@diegidio.name> - 2020-07-26 02:11 -0700
Re: when to use a struct(ure) or a class? Öö Tiib <ootiib@hot.ee> - 2020-07-27 08:37 -0700
Re: when to use a struct(ure) or a class? Julio Di Egidio <julio@diegidio.name> - 2020-07-25 00:02 -0700
Re: when to use a struct(ure) or a class? "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2020-07-25 09:16 +0200
Re: when to use a struct(ure) or a class? Julio Di Egidio <julio@diegidio.name> - 2020-07-25 00:30 -0700
csiph-web