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

C / C++ / MFC

 
GeneralRe: C++ class pointers Pin
peterchen12-Apr-10 0:04
peterchen12-Apr-10 0:04 
GeneralRe: C++ class pointers Pin
Joe Woodbury12-Apr-10 6:30
professionalJoe Woodbury12-Apr-10 6:30 
GeneralRe: C++ class pointers Pin
peterchen12-Apr-10 20:27
peterchen12-Apr-10 20:27 
GeneralRe: C++ class pointers Pin
Tim Craig11-Apr-10 17:32
Tim Craig11-Apr-10 17:32 
GeneralRe: C++ class pointers Pin
rupeshkp72811-Apr-10 19:30
rupeshkp72811-Apr-10 19:30 
GeneralRe: C++ class pointers Pin
peterchen12-Apr-10 20:33
peterchen12-Apr-10 20:33 
GeneralRe: C++ class pointers Pin
Tim Craig12-Apr-10 21:00
Tim Craig12-Apr-10 21:00 
AnswerRe: C++ class pointers Pin
Emilio Garavaglia11-Apr-10 20:58
Emilio Garavaglia11-Apr-10 20:58 
There is no unique answer, since it mostly depend on the semantics your class intended to be used and on the semantic of the resource (memory is a particular cas of resource, but having an HANDLE instead of an int* doesn't change the nature of your question) is planned to be represented.

The first thing to decide is what should happen when an instance of your class is assigned to another. Should both the classes refer to the same resource (that is: whatever modification required from both will act on the same object) or should them refer to different resources (that is: you need shallow or deep copy)?
Or should one instance represent one resource, hence no copy/assignment can be done and your classes must always pass by reference?)

The second thing to decide is the kind of "ownership" your class has on the resource: Does it own it (has the right to destroy it?) Is it an exclusive owner? Can it pass the ownership to somebody else? Should it share the ownership with other copies?

The following table may help:

no copy shallow
deep
no ownership use dumb pointers and disable copy and assing use dumb pointer and don't care NO SENSE
exclusive delete on destruction, disable copy/assign  NO SENSE implement copy and assign to create resource copies
pass-through NO SENSE use auto_ptr or implement equivalent semantic (transef
the pointer to the copy and make the original pointer null)
NO SENSE
sharing NO SENSE use reference counting or a reference counting capable
pointer (like shared_ptr)
NO SENSE


A third thing to decide is how your class acquire the resource: does it create it? Does it get it from a manages? is it created outside and passed to be handled?

As you see, there are many choices, some optimal in certain cases, some optimal in other.

2 bugs found.
> recompile ...
65534 bugs found.
D'Oh! | :doh:


QuestionC++Linking Classes/.cpp files to run one after other? Pin
FinalDecap11-Apr-10 5:59
FinalDecap11-Apr-10 5:59 
AnswerRe: C++Linking Classes/.cpp files to run one after other? Pin
Cedric Moonen11-Apr-10 20:57
Cedric Moonen11-Apr-10 20:57 
QuestionArray indexes Pin
Farraj10-Apr-10 23:46
Farraj10-Apr-10 23:46 
AnswerRe: Array indexes Pin
Nelek11-Apr-10 0:26
protectorNelek11-Apr-10 0:26 
AnswerRe: Array indexes Pin
Saurabh.Garg11-Apr-10 2:01
Saurabh.Garg11-Apr-10 2:01 
AnswerRe: Array indexes Pin
Luc Pattyn11-Apr-10 2:15
sitebuilderLuc Pattyn11-Apr-10 2:15 
AnswerRe: Array indexes Pin
Farraj11-Apr-10 3:04
Farraj11-Apr-10 3:04 
GeneralRe: Array indexes Pin
Luc Pattyn11-Apr-10 3:30
sitebuilderLuc Pattyn11-Apr-10 3:30 
GeneralRe: Array indexes Pin
Farraj11-Apr-10 11:27
Farraj11-Apr-10 11:27 
GeneralRe: Array indexes Pin
Luc Pattyn11-Apr-10 11:47
sitebuilderLuc Pattyn11-Apr-10 11:47 
GeneralRe: Array indexes Pin
Farraj14-Apr-10 8:30
Farraj14-Apr-10 8:30 
GeneralRe: Array indexes Pin
Farraj14-Apr-10 8:34
Farraj14-Apr-10 8:34 
GeneralRe: Array indexes Pin
Luc Pattyn14-Apr-10 8:34
sitebuilderLuc Pattyn14-Apr-10 8:34 
GeneralRe: Array indexes Pin
Farraj14-Apr-10 8:35
Farraj14-Apr-10 8:35 
AnswerRe: Array indexes Pin
Chris Losinger11-Apr-10 5:07
professionalChris Losinger11-Apr-10 5:07 
QuestionHow to fully custom draw combobox control, edit, arrow button and listbox included? Pin
kcynic10-Apr-10 23:16
kcynic10-Apr-10 23:16 
AnswerRe: How to fully custom draw combobox control, edit, arrow button and listbox included? Pin
Code-o-mat11-Apr-10 1:07
Code-o-mat11-Apr-10 1:07 

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.