Click here to Skip to main content
15,909,747 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: C++ question Pin
valikac27-Jul-06 9:01
valikac27-Jul-06 9:01 
GeneralRe: C++ question Pin
Alex_Y27-Jul-06 9:07
Alex_Y27-Jul-06 9:07 
GeneralRe: C++ question Pin
valikac27-Jul-06 9:20
valikac27-Jul-06 9:20 
GeneralRe: C++ question Pin
Alex_Y27-Jul-06 9:26
Alex_Y27-Jul-06 9:26 
GeneralRe: C++ question Pin
Alex_Y27-Jul-06 9:41
Alex_Y27-Jul-06 9:41 
AnswerRe: C++ question Pin
toxcct27-Jul-06 21:26
toxcct27-Jul-06 21:26 
GeneralRe: C++ question Pin
Alex_Y28-Jul-06 1:57
Alex_Y28-Jul-06 1:57 
GeneralRe: C++ question Pin
Zac Howland28-Jul-06 8:58
Zac Howland28-Jul-06 8:58 
Alex_Y wrote:
Class, struct you can use either. Only in 2005 agregatable type like:

CFoo oFooV[] = {{...},{...}, {...}};


It worked on older versions of Microsoft's compiler because they didn't meet the standard for this particular case. You cannot set the values of protected/private members directly like this (there are ways to do it, but if you do them, you will quickly be beaten with a stick in any code-review).


Alex_Y wrote:
And never worry about private or protected members just take "this" pointer and add offset to access to the nesesarry field, and use it. Private, protected is only for compilers and school teachers, they like those restrictions.


I do hope you are joking. If you truly believe this, never apply for any position if you see I'm the hiring manager.

To answer your original question, when you initialize the array in this manner:

CElement elements[] = { CElement(1, 2), CElement(2, 3), ...};

the elements in the array invoke the copy-assignment operator for each element. Thus, the elements themselves will be destroyed, but the values they hold will be copied into your array. For simple cases like this (where your data is just primitive types), you can get away without creating a copy constructor/copy-assignment operator; however, if you had a pointer to heap memory that your class was controlling, only the pointer value would be copied (and since the data in the original would be cleaned up, the pointer would be looking to a place in memory that was no longer allocated). You should get in the habit of creating copy constructors and copy-assignment operators (even if you mark them as private so they can't be invoked).



If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week

Zac

Questionfunction header = 0 Pin
Jay0327-Jul-06 8:38
Jay0327-Jul-06 8:38 
AnswerRe: function header = 0 Pin
valikac27-Jul-06 9:03
valikac27-Jul-06 9:03 
GeneralRe: function header = 0 Pin
Jay0327-Jul-06 9:04
Jay0327-Jul-06 9:04 
GeneralRe: function header = 0 Pin
Alex_Y27-Jul-06 9:15
Alex_Y27-Jul-06 9:15 
AnswerRe: function header = 0 Pin
markkuk27-Jul-06 11:42
markkuk27-Jul-06 11:42 
QuestionHow to Load Bitmap in CImageList from outside????? [modified] Pin
MacGadger27-Jul-06 8:00
MacGadger27-Jul-06 8:00 
QuestionRe: How to Load Bitmap in CImageList from outside????? Pin
Hamid_RT27-Jul-06 22:44
Hamid_RT27-Jul-06 22:44 
QuestionMAKEWORD macro Pin
kitty527-Jul-06 7:51
kitty527-Jul-06 7:51 
AnswerRe: MAKEWORD macro Pin
toxcct27-Jul-06 7:58
toxcct27-Jul-06 7:58 
AnswerRe: MAKEWORD macro Pin
kitty527-Jul-06 8:11
kitty527-Jul-06 8:11 
QuestionMS Access and CFileDialog conflict. Pin
na.nu27-Jul-06 7:50
na.nu27-Jul-06 7:50 
QuestionRe: MS Access and CFileDialog conflict. Pin
David Crow27-Jul-06 8:15
David Crow27-Jul-06 8:15 
AnswerRe: MS Access and CFileDialog conflict. Pin
Steve S27-Jul-06 21:51
Steve S27-Jul-06 21:51 
QuestionRe: MS Access and CFileDialog conflict. Pin
na.nu3-Aug-06 6:30
na.nu3-Aug-06 6:30 
AnswerRe: MS Access and CFileDialog conflict. Pin
Steve S9-Aug-06 1:52
Steve S9-Aug-06 1:52 
QuestionOpinions wanted Pin
Wes Aday27-Jul-06 4:40
professionalWes Aday27-Jul-06 4:40 
AnswerRe: Opinions wanted Pin
David Crow27-Jul-06 4:46
David Crow27-Jul-06 4:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.