C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 23rd, 2006, 01:06 PM
peenie's Avatar
peenie peenie is offline
Google Relay Server
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Oct 2003
Location: Oh christ I don't even know any more.
Posts: 1,812 peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)  Folding Points: 9953 Folding Title: Novice Folder
Time spent in forums: 2 Weeks 1 Day 19 h 12 m 24 sec
Reputation Power: 437
Send a message via AIM to peenie Send a message via MSN to peenie
Class vs. struct.

In C++, struct and class are synonyms. The only difference is the default access specifier of the members. I can never decide when to type "struct" or when to type "class". The line always seemed so fuzzy to me. I've been at this for years, but when it comes to struct vs class, consistency in my coding style suffers because I can never make up my mind.

Typically, I use struct when I just have a collection of public member data with no member functions. I use class when I have a conceptual object I'd like to represent, or when I start adding some more complex member functions.

When I use struct, as I add more member functions, I find myself stressing the fact that the functions are for "convenience" only -- perhaps to justify my use of "struct" instead of "class". But I really can never decide. It's unfortunate that the "struct" keyword still exists in C++.

What do you guys think?
__________________
OMG RAVER CHICKS!!
On a related note: C/C++ Programming Tutorials


"Science is based on reality staying the same, and Nature ignores what humans vote upon." -- Bill Beaty
"Three litres of sherry up the butt can only be described as astounding." -- Darwin Awards

Reply With Quote
  #2  
Old July 23rd, 2006, 01:45 PM
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2004
Posts: 1,676 Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 3 Days 8 h 23 m 46 sec
Reputation Power: 132
I generally think of a struct for PODS, and a class as something non-POD.
Quote:
Originally Posted by Wikipedia
Plain Old Data Structures in C++ would not contain any member functions and would not use inheritance. They would most naturally be represented as structs.
__________________
Any advertisement triggered by IntelliTxt in this post is not endorsed by the author of this post.

Last edited by Dave Sinkula : July 23rd, 2006 at 01:48 PM.

Reply With Quote
  #3  
Old July 23rd, 2006, 02:43 PM
peenie's Avatar
peenie peenie is offline
Google Relay Server
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Oct 2003
Location: Oh christ I don't even know any more.
Posts: 1,812 peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)  Folding Points: 9953 Folding Title: Novice Folder
Time spent in forums: 2 Weeks 1 Day 19 h 12 m 24 sec
Reputation Power: 437
Send a message via AIM to peenie Send a message via MSN to peenie
Me too. But then, consider this. You have this struct:

Code:
struct Info {
  int a;
  char *b;
  double c;
}


All is well. But now you want to add some functions. Perhaps a convenient way to initialize all the values, and a convenient way to create a duplicate copy, and I guess a convenient way to free the structure too:

Code:
Info * alloc_info (void);
Info * copy_info (const Info *info);
void free_info (Info *info);


That's all good and well but, you're using C++. If you don't want to stick to C-style coding like that, you may be tempted to do:

Code:
struct Info {

  int a;
  char *b;
  double c;

  Info (void);
  Info (const Info &);
  Info (const Info *);
  ~Info (void);

}


Generated code is pretty much exactly the same, as is the functionality and design, but the code is arguably easier to read and more importantly, consistent with the classes that you have scattered throughout the rest of the program (if not mixing two styles in the same app is important to you).

So now what? Change it to a class? But it's really just a PODS with the convenient utility functions as members instead of non-members. So maybe it should still be a struct.

Last edited by peenie : July 25th, 2006 at 09:25 PM.

Reply With Quote
  #4  
Old July 23rd, 2006, 02:52 PM
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2004
Posts: 1,676 Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 3 Days 8 h 23 m 46 sec
Reputation Power: 132
Quote:
Originally Posted by peenie
So now what? Change it to a class? But it's really just a POD with the convenient utility functions as members instead of non-members. So maybe it should still be a struct.
I would likely change it to a struct because it now has member functions so it stopped being POD. I also see a struct in C++ as being something that compiles as a struct in C.
Comments on this post
peenie agrees!
salem agrees!

Reply With Quote
  #5  
Old July 23rd, 2006, 03:01 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,142 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 4 Days 33 m 48 sec
Reputation Power: 1974
In practice, I generally agree Dave. If I'm going to use it as I would a struct in C, then I go with a struct. Otherwise, it'll be a class.

However, in my last major C++ project (also my first, back around '93) we discovered on our own that we could add methods to a struct -- we'd never seen it actually discussed in any books, but the ARM suggested that it might be possible, so we gave it a shot and it worked. But the furtherest we would ever take it was to give constructors and destructors to the structs that contained pointers to dynamically created data. I guess that we could have extended that idea to to converting input and output values (eg, store angles internally as radians, but receive input and provide output as degrees, minutes, seconds). Anything more (or even that) and we'd use a class. As it was, we thought we were getting away with something we shouldn't have with those constructors and destructors.
Comments on this post
peenie agrees: rep'd out though
salem agrees: I'd go along with that as well

Last edited by dwise1_aol : July 23rd, 2006 at 03:29 PM.

Reply With Quote
  #6  
Old July 23rd, 2006, 10:08 PM
nattylife nattylife is offline
Closet coder
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2005
Location: Plantation, FL <---south florida
Posts: 1,431 nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 13 h 33 m 57 sec
Reputation Power: 152
Send a message via AIM to nattylife
for me a struct is just a "simple" hetergenous data type. you have some set of different types that all relate to some logical unit. a class (which is creating a "viable object") woul be needed for being some self contained entity. it can take care of its own members and is a base for inheritance or is inheriting from some base class. its something more, for lack of better words, more OO.
Comments on this post
peenie agrees: well, since i'm on a roll with the rep button...
salem agrees: More sound words on the subject
__________________

Reply With Quote
  #7  
Old July 25th, 2006, 01:52 AM
Andrew80's Avatar
Andrew80 Andrew80 is offline
Advanced Programmer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Malaysia
Posts: 452 Andrew80 User rank is Sergeant Major (2000 - 5000 Reputation Level)Andrew80 User rank is Sergeant Major (2000 - 5000 Reputation Level)Andrew80 User rank is Sergeant Major (2000 - 5000 Reputation Level)Andrew80 User rank is Sergeant Major (2000 - 5000 Reputation Level)Andrew80 User rank is Sergeant Major (2000 - 5000 Reputation Level)Andrew80 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 13 h 16 m 32 sec
Reputation Power: 40
Send a message via MSN to Andrew80 Send a message via Yahoo to Andrew80
I normally use structs when I need all data to be public and there is no inheritance on the data structure.

Else , i will use a class because its clearer to read in the code.
Comments on this post
peenie agrees: you should have another green block too, just because.
__________________
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music."
- Kristin Wilson, Nintendo, Inc., 1989.

Reply With Quote
  #8  
Old July 25th, 2006, 12:52 PM
X.Cyclop X.Cyclop is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Location: Israel
Posts: 66 X.Cyclop Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 16 h 44 m 39 sec
Reputation Power: 0
Send a message via ICQ to X.Cyclop Send a message via MSN to X.Cyclop Send a message via Yahoo to X.Cyclop
Struct is part of Structured Programming (C), and Classes are part of Object-Oriented Programming (C++, Java, C#).
Comments on this post
peenie agrees!

Reply With Quote
  #9  
Old July 25th, 2006, 09:23 PM
peenie's Avatar
peenie peenie is offline
Google Relay Server
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Oct 2003
Location: Oh christ I don't even know any more.
Posts: 1,812 peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)  Folding Points: 9953 Folding Title: Novice Folder
Time spent in forums: 2 Weeks 1 Day 19 h 12 m 24 sec
Reputation Power: 437
Send a message via AIM to peenie Send a message via MSN to peenie
Quote:
Originally Posted by Andrew80
I normally use structs when I need all data to be public and there is no inheritance on the data structure.


That's pretty much my current attitude as well.

Quote:
Originally Posted by Dave Sinkula
I would likely change it to a struct because it now has member functions so it stopped being POD.


But now you'd have a struct with lots of public members. Granted that's not a problem, but most code that you see that uses classes has accessor functions for all of its members. If I were to change it to a "class", should I then put a layer of abstraction over all the member access just to be consistent? I wouldn't want to do that, but it could easily lead to a weird mix of styles in the same code.

Quote:
I also see a struct in C++ as being something that compiles as a struct in C.


That seems to make sense.

Quote:
Originally Posted by dwise1_aol
However, in my last major C++ project (also my first, back around '93) we discovered on our own that we could add methods to a struct... As it was, we thought we were getting away with something we shouldn't have with those constructors and destructors.


As far as syntax itself goes; that's not really that "sideways". The two keywords are synonyms in C++ (aside from the default access policies). They are handled the same internally as well. And actually, on my version of GCC at least, the following code compiles with no warnings:

Code:
class Whatever {
public:
  int _;
};

void function1 (class Whatever *) {
}

void function2 (struct Whatever *) {
}

int main (int, char **) {
  Whatever a;
  function1(&a);
  function2(&a);
  return 0;
}


I'm pretty sure the only reason the "struct" keyword is still around at all in C++ is for C compatibility, which, combined with...

Quote:
Originally Posted by X.Cyclop
Struct is part of Structured Programming (C), and Classes is part of Object Oriented Programming (C++, Java, C#).


...is starting to convince me that I won't be using "struct" in C++ ever, for any reason (although it's convenient not having to type "public").
Comments on this post
salem agrees: Nice comparisons.

Reply With Quote
  #10  
Old July 25th, 2006, 10:04 PM
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2004
Posts: 1,676 Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 3 Days 8 h 23 m 46 sec
Reputation Power: 132
Quote:
Originally Posted by peenie
(although it's convenient not having to type "public").
Private constructors only!?!

Reply With Quote
  #11  
Old July 25th, 2006, 10:08 PM
peenie's Avatar
peenie peenie is offline
Google Relay Server
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Oct 2003
Location: Oh christ I don't even know any more.
Posts: 1,812 peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)  Folding Points: 9953 Folding Title: Novice Folder
Time spent in forums: 2 Weeks 1 Day 19 h 12 m 24 sec
Reputation Power: 437
Send a message via AIM to peenie Send a message via MSN to peenie
Quote:
Originally Posted by Dave Sinkula
Private constructors only!?!


Well, there's some very fine print in the standard that says that you must use private constructors when allocating objects on the write-only heap.
Comments on this post
nattylife agrees: i think this post needs more repping from peenie

Reply With Quote
  #12  
Old July 28th, 2006, 03:40 PM
KitKat77's Avatar
KitKat77 KitKat77 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Location: planet<earth_like_t>
Posts: 365 KitKat77 User rank is First Lieutenant (10000 - 20000 Reputation Level)KitKat77 User rank is First Lieutenant (10000 - 20000 Reputation Level)KitKat77 User rank is First Lieutenant (10000 - 20000 Reputation Level)KitKat77 User rank is First Lieutenant (10000 - 20000 Reputation Level)KitKat77 User rank is First Lieutenant (10000 - 20000 Reputation Level)KitKat77 User rank is First Lieutenant (10000 - 20000 Reputation Level)KitKat77 User rank is First Lieutenant (10000 - 20000 Reputation Level)KitKat77 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 9 h 53 m 7 sec
Reputation Power: 147
Ok, I just had to post this since I just learned about it. Did you guys know that there exists a Joint Strike Fighter C++ Coding Standard? Here what it has to say about struct vs. class:


Quote:
4.10.2 Considerations Regarding Access Rights
Roughly two types of classes exist: those that essentially aggregate data and those that provide an abstraction while maintaining a well-defined state or invariant. The following rules provide guidance in this regard.
AV Rule 65
A structure should be used to model an entity that does not require an invariant.
AV Rule 66
A class should be used to model an entity that maintains an invariant.
AV Rule 67
Public and protected data should only be used in structs—not classes.

Rationale: A class is able to maintain its invariant by controlling access to its data. However, a class cannot control access to its members if those members non-private. Hence all data in a class should be private.
Exception: Protected members may be used in a class as long as that class does not participate in a client interface. See AV Rule 88.


Hey, if it's good enough for a military jet fighter, it oughta be good enough for you!

Reply With Quote
  #13  
Old July 28th, 2006, 03:59 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,390 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 1 Day 22 h 36 m 15 sec
Reputation Power: 4080
Lots of corporations have coding standards. IIRC, the aviation coding standards were partly based off the ones adopted in the auto industry. I could swear I saw the aviation standards one somewhere a few weeks ago (DDJ perhaps?). One of our members (Clifford perhaps?) alludes to the auto industry's standards of coding, MISRA, quite often.

[edit]Now I remember where I saw the link. Bjarne Stroustrup references it in his FAQ: http://www.research.att.com/~bs/bs_...coding-standard and points to the same document on AT&T's server. Seems he had a hand in describing the coding standard [/edit]
Comments on this post
salem agrees: Good call on the coding standards, I've used MISRA once before.
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Reply With Quote
  #14  
Old July 28th, 2006, 07:58 PM
peenie's Avatar
peenie peenie is offline
Google Relay Server
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Oct 2003
Location: Oh christ I don't even know any more.
Posts: 1,812 peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)  Folding Points: 9953 Folding Title: Novice Folder
Time spent in forums: 2 Weeks 1 Day 19 h 12 m 24 sec
Reputation Power: 437
Send a message via AIM to peenie Send a message via MSN to peenie
Quote:
Originally Posted by KitKat77
Hey, if it's good enough for a military jet fighter, it oughta be good enough for you!


Hmm; that's a nice clear way of looking at it too. Although it still seems like there's that fuzzy gray area where you have an entity with no invariants but convenient operations you can perform on it, where member functions would be the most convenient way to handle it.

Although a constructor/copy constructor/destructor combo on a struct with dynamically allocated data in it would have some constraints placed on it so, I guess in that case, I'm wrong to call the *tors "convenience" functions and it would make sense to use class for that instead.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Class vs. struct.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap