| | |
modifying the same member of many objects
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
How would you change the same member of many objects of the same class (or structure if possible)?
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?
C++ Syntax (Toggle Plain Text)
struct point { float x, y, z; } point a, b, c; a.x += 20; // b.x += 20; // now how would i do this in one statement? 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?
Well I need each x member to have different instances, like this:
and yet be able to modify them all, even if there were hundreds of instances of point.
C++ Syntax (Toggle Plain Text)
struct point { float x, y, z; } point a, b, c; a.x = 10; b.x = -50; c.x = 2000.3258; a.x += 20; // b.x += 20; // now how would i do this in one statement? c.x += 20; //
and yet be able to modify them all, even if there were hundreds of instances of point.
•
•
•
•
Well I need each x member to have different instances, like this:
C++ Syntax (Toggle Plain Text)
struct point { float x, y, z; } point a, b, c; a.x = 10; b.x = -50; c.x = 2000.3258; a.x += 20; // b.x += 20; // now how would i do this in one statement? c.x += 20; //
and yet be able to modify them all, even if there were hundreds of instances of point.
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.
![]() |
Similar Threads
- Help me for friend classes and using templates (C++)
- Passing Arrays of Objects to Member Functions (C++)
- performance benefit by not calling static member function by object (C)
- static friend function (C)
Other Threads in the C++ Forum
- Previous Thread: Help with fstream
- Next Thread: need a bit of help with my homework(operator overloading)
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






