Click here to Skip to main content
15,890,557 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionDisk Wipe Pin
Member 862075915-Oct-13 23:52
Member 862075915-Oct-13 23:52 
AnswerRe: Disk Wipe Pin
Member 862075916-Oct-13 2:11
Member 862075916-Oct-13 2:11 
AnswerRe: Disk Wipe Pin
Vaclav_16-Oct-13 14:43
Vaclav_16-Oct-13 14:43 
SuggestionRe: Disk Wipe Pin
SoMad16-Oct-13 17:17
professionalSoMad16-Oct-13 17:17 
AnswerRe: Disk Wipe Pin
Albert Holguin17-Oct-13 5:33
professionalAlbert Holguin17-Oct-13 5:33 
AnswerRe: Disk Wipe Pin
TheKingofdemon3318-Oct-13 9:14
TheKingofdemon3318-Oct-13 9:14 
QuestionPolymorphism & Assignment Op. & Copy Constructors in C++ Pin
federico.strati15-Oct-13 2:16
federico.strati15-Oct-13 2:16 
AnswerRe: Polymorphism & Assignment Op. & Copy Constructors in C++ Pin
Aescleal21-Oct-13 4:45
Aescleal21-Oct-13 4:45 
That looks like a shed load of code just to implement copying and assignment. Are you sure that copying objects of arbitrary types is both necessary to your design and won't turn into a complete millstone around your development team's neck? They might not thank you when they have to grind that lot out again to implement a new class? I'm also wincing at how the assignment operators are written - the canonical way you write an assignment operator in C++ is to use a copy and swap.

So... What would I suggest? Firstly go back to your design and see if it can be reworked to use a set of relatively simple principles:

- value types have no polymorphic behaviour and are copy constructable and assignable if appropriate. Use copy and swap to write the assignment operator for a value type

- polymorphic types are accessed through interfaces. Don't assign or copy the objects themselves, reference them through pointers or references to the interfaces they implement. The only place that knows the concrete type of a polymorphic type is the lump of code that creates the object

- don't use implementation inheritance. Containment gives far less headaches

- minimise manual memory management wherever possible. Use parameterise from above (PFA) and objects created on the stack wherever possible. If you write a delete statement pinch yourself and look at using std::unique_ptr or std::shared_ptr instead. RAII is your friend

- make everything exception safe but don't handle exceptions in too many places. One try/catch set in a function

If there's still a need to deep copy objects through pointers to arbitrary base classes then consider implementing a clonable interface. Never slice objects - once you lop off the context you can never get it back.
GeneralRe: Polymorphism & Assignment Op. & Copy Constructors in C++ Pin
federico.strati21-Oct-13 22:04
federico.strati21-Oct-13 22:04 
GeneralRe: Polymorphism & Assignment Op. & Copy Constructors in C++ Pin
Aescleal21-Oct-13 23:15
Aescleal21-Oct-13 23:15 
GeneralRe: Polymorphism & Assignment Op. & Copy Constructors in C++ Pin
federico.strati22-Oct-13 0:12
federico.strati22-Oct-13 0:12 
QuestionSQLFetchScroll is failing if database column contains NULL value Pin
Ashish Ranjan Mishra14-Oct-13 21:13
Ashish Ranjan Mishra14-Oct-13 21:13 
AnswerRe: SQLFetchScroll is failing if database column contains NULL value Pin
Rajesh R Subramanian14-Oct-13 22:24
professionalRajesh R Subramanian14-Oct-13 22:24 
GeneralRe: SQLFetchScroll is failing if database column contains NULL value Pin
Ashish Ranjan Mishra14-Oct-13 23:24
Ashish Ranjan Mishra14-Oct-13 23:24 
GeneralRe: SQLFetchScroll is failing if database column contains NULL value Pin
Rajesh R Subramanian14-Oct-13 23:29
professionalRajesh R Subramanian14-Oct-13 23:29 
GeneralRe: SQLFetchScroll is failing if database column contains NULL value Pin
Rajesh R Subramanian14-Oct-13 23:34
professionalRajesh R Subramanian14-Oct-13 23:34 
GeneralRe: SQLFetchScroll is failing if database column contains NULL value Pin
Ashish Ranjan Mishra15-Oct-13 9:41
Ashish Ranjan Mishra15-Oct-13 9:41 
GeneralRe: SQLFetchScroll is failing if database column contains NULL value Pin
Rajesh R Subramanian15-Oct-13 11:30
professionalRajesh R Subramanian15-Oct-13 11:30 
QuestionPassing class pointer via socket Pin
Don Guy14-Oct-13 13:09
Don Guy14-Oct-13 13:09 
AnswerRe: Passing class pointer via socket Pin
Richard Andrew x6414-Oct-13 14:34
professionalRichard Andrew x6414-Oct-13 14:34 
GeneralRe: Passing class pointer via socket Pin
pasztorpisti14-Oct-13 21:50
pasztorpisti14-Oct-13 21:50 
AnswerRe: Passing class pointer via socket Pin
Erudite_Eric14-Oct-13 17:10
Erudite_Eric14-Oct-13 17:10 
AnswerRe: Passing class pointer via socket Pin
ExcellentOrg14-Oct-13 21:20
ExcellentOrg14-Oct-13 21:20 
AnswerRe: Passing class pointer via socket Pin
Rajesh R Subramanian14-Oct-13 22:43
professionalRajesh R Subramanian14-Oct-13 22:43 
AnswerRe: Passing class pointer via socket Pin
Albert Holguin15-Oct-13 6:39
professionalAlbert Holguin15-Oct-13 6:39 

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.