Click here to Skip to main content
15,033,418 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Why isn't the copy constructor called Pin
_Flaviu22-Sep-20 19:48
Member_Flaviu22-Sep-20 19:48 
GeneralRe: Why isn't the copy constructor called Pin
Mircea Neacsu23-Sep-20 1:45
mvaMircea 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
mvaMircea Neacsu23-Sep-20 1:56 
AnswerRe: Why isn't the copy constructor called - Solved Pin
Mircea Neacsu23-Sep-20 2:56
mvaMircea 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
mvaGreg Utas24-Sep-20 1:00 
GeneralRe: Why isn't the copy constructor called - Solved Pin
Mircea Neacsu24-Sep-20 2:51
mvaMircea 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':
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
mvaGreg Utas24-Sep-20 3:20 
Questioncompilers for pure assembly code Pin
CalinNegru(fearless_)19-Sep-20 0:46
MemberCalinNegru(fearless_)19-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
CalinNegru(fearless_)24-Sep-20 1:00
MemberCalinNegru(fearless_)24-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
Memberarnold_w10-Sep-20 4:54 
AnswerRe: Why do I get "undefined reference to..." when trying to call a C-function inside a .cpp-file? Pin
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
Memberarnold_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
mvaMircea 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
Memberarnold_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
mvaMircea 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
Memberarnold_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
Memberarnold_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.