Click here to Skip to main content
15,886,798 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Why isn't the copy constructor called Pin
_Flaviu22-Sep-20 19:48
_Flaviu22-Sep-20 19:48 
GeneralRe: Why isn't the copy constructor called Pin
Mircea Neacsu23-Sep-20 1:45
Mircea Neacsu23-Sep-20 1:45 
AnswerRe: Why isn't the copy constructor called Pin
Richard MacCutchan22-Sep-20 23:38
mveRichard MacCutchan22-Sep-20 23:38 
GeneralRe: Why isn't the copy constructor called Pin
Mircea Neacsu23-Sep-20 1:56
Mircea Neacsu23-Sep-20 1:56 
AnswerRe: Why isn't the copy constructor called - Solved Pin
Mircea Neacsu23-Sep-20 2:56
Mircea Neacsu23-Sep-20 2:56 
GeneralRe: Why isn't the copy constructor called - Solved Pin
Richard MacCutchan23-Sep-20 3:01
mveRichard MacCutchan23-Sep-20 3:01 
GeneralRe: Why isn't the copy constructor called - Solved Pin
Greg Utas24-Sep-20 1:00
professionalGreg Utas24-Sep-20 1:00 
GeneralRe: Why isn't the copy constructor called - Solved Pin
Mircea Neacsu24-Sep-20 2:51
Mircea Neacsu24-Sep-20 2:51 
On the contrary: I'm quite unimpressed ("we are not amused").

You know what they say that C makes it easy to shoot yourself in the foot and C++ gives you a bazooka. In this case I's say you walk with hand grenades in your pocket; safety pins are optional.

Note that even in the variant that 'works':
C++
B bobj (aobj);
B* bbptr = new B (bobj);

bobj is susceptible to being optimized out of existence and turned back into the previous case.

To leave it to the compiler, or the compiler designer, if a function should be called or not, and to do it without even a warning, is unconscionable. Haven't researched the history of this section of the standard but I'd dare say that it dates back to the '03 time and the 'efficiency wars'. That was put to rest with the '11 move constructors and assignment operators but probably that section of the standard slipped through.

In fairness, I should say that it's not something that happens too often. This is the first time I run into the issue but I'll keep it in mind for the future.
Mircea

GeneralRe: Why isn't the copy constructor called - Solved Pin
Greg Utas24-Sep-20 3:20
professionalGreg Utas24-Sep-20 3:20 
Questioncompilers for pure assembly code Pin
Calin Negru19-Sep-20 0:46
Calin Negru19-Sep-20 0:46 
AnswerRe: compilers for pure assembly code Pin
Richard MacCutchan19-Sep-20 2:24
mveRichard MacCutchan19-Sep-20 2:24 
AnswerRe: compilers for pure assembly code Pin
Joe Woodbury22-Sep-20 11:38
professionalJoe Woodbury22-Sep-20 11:38 
AnswerRe: compilers for pure assembly code Pin
Calin Negru24-Sep-20 1:00
Calin Negru24-Sep-20 1:00 
QuestionWhy do I get "undefined reference to..." when trying to call a C-function inside a .cpp-file? Pin
arnold_w10-Sep-20 4:54
arnold_w10-Sep-20 4:54 
AnswerRe: Why do I get "undefined reference to..." when trying to call a C-function inside a .cpp-file? PinPopular
Richard MacCutchan10-Sep-20 5:30
mveRichard MacCutchan10-Sep-20 5:30 
QuestionIcons for Executable Files - SOLVED Pin
Richard Andrew x649-Sep-20 14:55
professionalRichard Andrew x649-Sep-20 14:55 
QuestionWhat's the closest thing to an anonymous struct/array I can achieve that compiles with GCC? Pin
arnold_w9-Sep-20 8:16
arnold_w9-Sep-20 8:16 
AnswerRe: What's the closest thing to an anonymous struct/array I can achieve that compiles with GCC? Pin
Mircea Neacsu9-Sep-20 11:20
Mircea Neacsu9-Sep-20 11:20 
GeneralRe: What's the closest thing to an anonymous struct/array I can achieve that compiles with GCC? Pin
arnold_w9-Sep-20 11:33
arnold_w9-Sep-20 11:33 
AnswerRe: What's the closest thing to an anonymous struct/array I can achieve that compiles with GCC? Pin
Mircea Neacsu9-Sep-20 12:11
Mircea Neacsu9-Sep-20 12:11 
GeneralRe: What's the closest thing to an anonymous struct/array I can achieve that compiles with GCC? Pin
arnold_w9-Sep-20 12:28
arnold_w9-Sep-20 12:28 
GeneralRe: What's the closest thing to an anonymous struct/array I can achieve that compiles with GCC? Pin
Randor 9-Sep-20 12:44
professional Randor 9-Sep-20 12:44 
AnswerRe: What's the closest thing to an anonymous struct/array I can achieve that compiles with GCC? Pin
Joe Woodbury9-Sep-20 12:38
professionalJoe Woodbury9-Sep-20 12:38 
GeneralRe: What's the closest thing to an anonymous struct/array I can achieve that compiles with GCC? Pin
arnold_w9-Sep-20 14:35
arnold_w9-Sep-20 14:35 
GeneralRe: What's the closest thing to an anonymous struct/array I can achieve that compiles with GCC? Pin
Joe Woodbury9-Sep-20 15:14
professionalJoe Woodbury9-Sep-20 15:14 

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.