Click here to Skip to main content
15,910,981 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: hard disk full while writing to file Pin
Jonathon Lockett3-Jul-01 12:53
Jonathon Lockett3-Jul-01 12:53 
GeneralI thought I understood polymorphism Pin
Alex Griffing3-Jul-01 12:05
Alex Griffing3-Jul-01 12:05 
GeneralRe: I thought I understood polymorphism Pin
Alex Griffing3-Jul-01 12:16
Alex Griffing3-Jul-01 12:16 
GeneralRe: I thought I understood polymorphism Pin
Ben Burnett3-Jul-01 13:40
Ben Burnett3-Jul-01 13:40 
GeneralRe: I thought I understood polymorphism Pin
Alex Griffing3-Jul-01 13:57
Alex Griffing3-Jul-01 13:57 
GeneralRe: I thought I understood polymorphism Pin
Stan Shannon3-Jul-01 14:40
Stan Shannon3-Jul-01 14:40 
GeneralRe: I thought I understood polymorphism Pin
Alex Griffing3-Jul-01 16:33
Alex Griffing3-Jul-01 16:33 
GeneralRe: I thought I understood polymorphism Pin
Stan Shannon3-Jul-01 17:38
Stan Shannon3-Jul-01 17:38 
The entire point of construction is to give an object the opportunity to uniquely initialize itself. Usually the way it is done is something like this:

class foo1
{
foo1() { m_x = 0; m_y = 0; m_y = 0; }
};

class foo2 : public foo1
{
// call the base class' constructor as you construct the derived class.
foo2(): foo1() { m_xx = 0; m_yy = 0; mm_zz = 0; }

};
class anotherfoo : public foo1
{
anotherfoo (): foo1() { m_xx = 0; m_yy = 0; mm_zz = 0; }
};

Now, both base and derived classs are properly initialize when you declare a foo2:


foouser::UseFoo()
{
foo2 footoo;
anotherfoo fooalso;

// or

foo2* pfootoo = new foo2();
anotherfoo* pfooalso = new anotherfoo();
};

So, I guess I don't really see what your issue is with initializing the objects. At this point, polymorphism has not even become
an issue.

The "Virtual Constructor" is simply a way to ensure a correct object is created if you do something like this:
(As I typically keep my objects in paramatarized lists, this technique comes in handy)

foouser::UseFoo()
{
foo2 footoo;

DoSomethingElse( &footoo );
}

foouser::DoSomethingElse( foo* pfoo )
{
foo* pfooX = pfoo->Clone();// pfoo creates a copy of a foo2, or anotherfoo, if it was called with that.

//// use pfooX.
//// Obviously, for this example, I could have just used pfoo as is, but say I wanted to store a foo2 in its
//// current state for whatever reason, this is very convenient. The point is that my Constructor is now capable of
//// polymorphic behavior.
delete pfooX;
};

I believe you are technically right about the derived virtual bar() being redundant. But the rule of thumb, I think, is once virutal, always virtual. You can keep yourself out of a lot of trouble by keeping that in mind.

GeneralRe: I thought I understood polymorphism Pin
3-Jul-01 21:12
suss3-Jul-01 21:12 
GeneralRe: I thought I understood polymorphism Pin
Malcolm McMahon3-Jul-01 23:24
Malcolm McMahon3-Jul-01 23:24 
QuestionWho can give me a help???? Pin
3-Jul-01 11:26
suss3-Jul-01 11:26 
Questionmultiple active windows in MDI? Pin
Jake Palmer3-Jul-01 11:15
Jake Palmer3-Jul-01 11:15 
AnswerRe: multiple active windows in MDI? Pin
3-Jul-01 12:19
suss3-Jul-01 12:19 
GeneralRe: multiple active windows in MDI? Pin
Jake Palmer3-Jul-01 14:31
Jake Palmer3-Jul-01 14:31 
GeneralRe: multiple active windows in MDI? Pin
Ben Burnett3-Jul-01 18:45
Ben Burnett3-Jul-01 18:45 
AnswerRe: multiple active windows in MDI? Pin
#realJSOP4-Jul-01 1:06
professional#realJSOP4-Jul-01 1:06 
AnswerRe: multiple active windows in MDI? Pin
Jose Cruz4-Jul-01 11:35
Jose Cruz4-Jul-01 11:35 
GeneralGetCurrentDirectory Pin
3-Jul-01 10:45
suss3-Jul-01 10:45 
GeneralRe: GetCurrentDirectory Pin
Ghazi H. Wadi3-Jul-01 10:50
Ghazi H. Wadi3-Jul-01 10:50 
GeneralWord and WM_VSCROLL Pin
BobMatura3-Jul-01 10:08
BobMatura3-Jul-01 10:08 
Questionhow to include source code Pin
uma3-Jul-01 9:26
uma3-Jul-01 9:26 
AnswerRe: how to include source code Pin
Jonathon Lockett3-Jul-01 12:54
Jonathon Lockett3-Jul-01 12:54 
GeneralSoundBuffer problems. Pin
Daniel Selberg3-Jul-01 8:27
Daniel Selberg3-Jul-01 8:27 
Generalquestion about linking to a static library Pin
3-Jul-01 8:25
suss3-Jul-01 8:25 
GeneralRe: question about linking to a static library Pin
Stan Shannon3-Jul-01 8:52
Stan Shannon3-Jul-01 8:52 

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.