Click here to Skip to main content
15,887,485 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: C++ class initialization Pin
Albert Holguin20-Jan-15 8:05
professionalAlbert Holguin20-Jan-15 8:05 
GeneralRe: C++ class initialization Pin
CPallini20-Jan-15 9:14
mveCPallini20-Jan-15 9:14 
GeneralRe: C++ class initialization Pin
Albert Holguin20-Jan-15 9:57
professionalAlbert Holguin20-Jan-15 9:57 
GeneralRe: C++ class initialization Pin
CPallini20-Jan-15 10:26
mveCPallini20-Jan-15 10:26 
General[SOLVED] Re: C++ class initialization Pin
Vaclav_22-Jan-15 8:00
Vaclav_22-Jan-15 8:00 
GeneralRe: [SOLVED] Re: C++ class initialization Pin
CPallini22-Jan-15 9:06
mveCPallini22-Jan-15 9:06 
GeneralRe: [REOPEN} C++ class initialization and scheme Pin
Vaclav_23-Jan-15 6:49
Vaclav_23-Jan-15 6:49 
GeneralRe: [REOPEN} C++ class initialization and scheme Pin
Mike Nordell2-Feb-15 10:14
Mike Nordell2-Feb-15 10:14 
Some basics:
Is-a = inheritance. If you inherit type B from A, then you can use type B as type A. Also see Liskov Substitution Principle (LSP).

Example:
class Shape { virtual void Draw() = 0; /* ... */ };
class Circle : public Shape { void Draw(); };


A Circle is-a Shape, so type Circle inherits type Shape. Note that this is all about behavior (interface), so you can treat a pointer or reference to any subclass of Shape as if it was a Shape with respect to Shape's interface (in this case a single Draw() function).

Has-a = aggregating.
Example:
class Canvas {
public:  void Draw();
private: set<Shape*> m_shapes;
};


A Canvas can hold one or more Shape's, of any concrete subtype, and most likely Canvas::Draw will iterate over the shapes it holds, calling their Draw method. For clarity, you may want to think of Canvas::Draw as Canvas::DrawShapes.

For the particular case where you are to have one, and only one, object of a specific type, you may want to have a look at making it a Singleton.

I hope this attempt at a simple explanation of the concepts can help you come up with a design. While drawing has nothing at all to do with USB, the concepts of inheritance and aggregation are the same. For project after project.

(NOTE: code-formatting was done for compactness, please do not copy as-is Smile | :) )
GeneralRe: [REOPEN} C++ class initialization and scheme Pin
Vaclav_2-Feb-15 10:57
Vaclav_2-Feb-15 10:57 
GeneralRe: [REOPEN} C++ class initialization and scheme Pin
Mike Nordell2-Feb-15 12:46
Mike Nordell2-Feb-15 12:46 
Questionbinary data to image VC++ Pin
Mukund Pradeep16-Jan-15 18:40
Mukund Pradeep16-Jan-15 18:40 
QuestionRe: binary data to image VC++ Pin
CPallini16-Jan-15 22:33
mveCPallini16-Jan-15 22:33 
AnswerRe: binary data to image VC++ Pin
Richard MacCutchan16-Jan-15 22:45
mveRichard MacCutchan16-Jan-15 22:45 
GeneralRe: binary data to image VC++ Pin
Mukund Pradeep19-Jan-15 18:39
Mukund Pradeep19-Jan-15 18:39 
GeneralRe: binary data to image VC++ Pin
Mukund Pradeep3-Feb-15 18:08
Mukund Pradeep3-Feb-15 18:08 
GeneralRe: binary data to image VC++ Pin
Richard MacCutchan3-Feb-15 22:42
mveRichard MacCutchan3-Feb-15 22:42 
GeneralRe: binary data to image VC++ Pin
Mukund Pradeep9-Feb-15 20:17
Mukund Pradeep9-Feb-15 20:17 
QuestionRe: binary data to image VC++ Pin
Richard MacCutchan9-Feb-15 22:10
mveRichard MacCutchan9-Feb-15 22:10 
AnswerRe: binary data to image VC++ Pin
Mukund Pradeep9-Feb-15 22:36
Mukund Pradeep9-Feb-15 22:36 
GeneralRe: binary data to image VC++ Pin
Richard MacCutchan9-Feb-15 23:20
mveRichard MacCutchan9-Feb-15 23:20 
GeneralRe: binary data to image VC++ Pin
Mukund Pradeep10-Feb-15 17:21
Mukund Pradeep10-Feb-15 17:21 
GeneralRe: binary data to image VC++ Pin
Richard MacCutchan10-Feb-15 21:22
mveRichard MacCutchan10-Feb-15 21:22 
GeneralRe: binary data to image VC++ Pin
Mukund Pradeep10-Feb-15 22:05
Mukund Pradeep10-Feb-15 22:05 
AnswerRe: binary data to image VC++ Pin
Chris Losinger18-Jan-15 8:49
professionalChris Losinger18-Jan-15 8:49 
Questioncan a function return WCHAR Pin
bkelly1316-Jan-15 6:07
bkelly1316-Jan-15 6: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.