modifying the same member of many objects

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2006
Posts: 38
Reputation: LieAfterLie is an unknown quantity at this point 
Solved Threads: 2
LieAfterLie's Avatar
LieAfterLie LieAfterLie is offline Offline
Light Poster

modifying the same member of many objects

 
0
  #1
Oct 23rd, 2006
How would you change the same member of many objects of the same class (or structure if possible)?

  1. struct point
  2. {
  3. float x, y, z;
  4. }
  5.  
  6. point a, b, c;
  7.  
  8. a.x += 20; //
  9. b.x += 20; // now how would i do this in one statement?
  10. c.x += 20; //

I don't see how inheritance or polymorphism would apply, and as far as I know they don't work with structures anyway, and I really have no need of classes. So how would I change all point::x members universally regardless of how many or what objects use it?
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: modifying the same member of many objects

 
0
  #2
Oct 23rd, 2006
How about declaring x as a static member of class point?
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 38
Reputation: LieAfterLie is an unknown quantity at this point 
Solved Threads: 2
LieAfterLie's Avatar
LieAfterLie LieAfterLie is offline Offline
Light Poster

Re: modifying the same member of many objects

 
0
  #3
Oct 23rd, 2006
Well I need each x member to have different instances, like this:


  1. struct point
  2. {
  3. float x, y, z;
  4. }
  5.  
  6. point a, b, c;
  7.  
  8. a.x = 10;
  9. b.x = -50;
  10. c.x = 2000.3258;
  11.  
  12. a.x += 20; //
  13. b.x += 20; // now how would i do this in one statement?
  14. c.x += 20; //



and yet be able to modify them all, even if there were hundreds of instances of point.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 89
Reputation: TylerSBreton is an unknown quantity at this point 
Solved Threads: 3
TylerSBreton's Avatar
TylerSBreton TylerSBreton is offline Offline
Junior Poster in Training

Re: modifying the same member of many objects

 
0
  #4
Oct 23rd, 2006
Originally Posted by LieAfterLie View Post
Well I need each x member to have different instances, like this:


  1. struct point
  2. {
  3. float x, y, z;
  4. }
  5.  
  6. point a, b, c;
  7.  
  8. a.x = 10;
  9. b.x = -50;
  10. c.x = 2000.3258;
  11.  
  12. a.x += 20; //
  13. b.x += 20; // now how would i do this in one statement?
  14. c.x += 20; //



and yet be able to modify them all, even if there were hundreds of instances of point.
How about creating an array of points, then using a loop to traverse each element of the array?
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 38
Reputation: LieAfterLie is an unknown quantity at this point 
Solved Threads: 2
LieAfterLie's Avatar
LieAfterLie LieAfterLie is offline Offline
Light Poster

Re: modifying the same member of many objects

 
0
  #5
Oct 24th, 2006
Okay, I'll use a multidimesional array to store the 'objects'. I just thought it would be helpful if I could name them different things and use the default copy constructor/copy assignment constructor, like b = a; or point top (c);. Don't you think such a member-modifying feature should be added to C++? It would be awesome.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: modifying the same member of many objects

 
0
  #6
Oct 24th, 2006
Originally Posted by LieAfterLie View Post
Don't you think such a member-modifying feature should be added to C++?
No.
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 38
Reputation: LieAfterLie is an unknown quantity at this point 
Solved Threads: 2
LieAfterLie's Avatar
LieAfterLie LieAfterLie is offline Offline
Light Poster

Re: modifying the same member of many objects

 
0
  #7
Oct 24th, 2006
Care to be a little more specific?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC