Click here to Skip to main content
15,900,258 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionMFC object CFormView Pin
karmendra_js28-Sep-05 23:11
karmendra_js28-Sep-05 23:11 
AnswerRe: MFC object CFormView Pin
prasad_som29-Sep-05 0:36
prasad_som29-Sep-05 0:36 
QuestionRe: MFC object CFormView Pin
karmendra_js29-Sep-05 0:54
karmendra_js29-Sep-05 0:54 
AnswerRe: MFC object CFormView Pin
Steen Krogsgaard30-Sep-05 3:07
Steen Krogsgaard30-Sep-05 3:07 
QuestionVirtual function Pin
karmendra_js28-Sep-05 23:06
karmendra_js28-Sep-05 23:06 
AnswerRe: Virtual function Pin
Cedric Moonen28-Sep-05 23:43
Cedric Moonen28-Sep-05 23:43 
Questionvtbl question when derived Pin
followait28-Sep-05 22:44
followait28-Sep-05 22:44 
AnswerRe: vtbl question when derived Pin
Steen Krogsgaard30-Sep-05 3:37
Steen Krogsgaard30-Sep-05 3:37 
1 is correct. However, A's vtable and B's vtable are different, although in this case the first entry in both tables will be the same (&A:testA). The first four bytes (in VC++6.0 at least) of the classes are the vtable ptr; in A it will point to A's vtable, in B it will point to B's vtable. That's how an A-ptr pointing to a B-object will know how to call B's version of an overloaded virtual function and not A's version.

If we expand on your example so the definitions are:
class A
{
   virtual testA();
   testA2();
}

class B:public A
{
   virtual testA();
   virtual testB();
   testA2();
   testB2();
}

then the object layout and the results of calling the members will be:
A: vptr ---> &A::testA

B: vptr ---> &B::testA()
             &B::testB()

// call members:
A a;
B b;
A* ab=&b // ab points to a B object, but the compiler sees it as an A object
a.testA()     // calls A::testA
a.testA2()    // calls A::testA2
b.testA()     // calls B::testA
b.testA2()    // calls B::testA2
b.testB()     // calls B::testB
b.testB2()    // calls B::testB2
ab->testA()   // calls B::testA - testA is virtual
ab->testA2()  // calls A::testA2 - testA2 is not virtual, the compiler thinks ab points to an A object
ab->testB()   // compiler error, A does not have member testB
ab->testB2()  // compiler error, A does not have member testB2


Hope this clarifies it.

Cheers
Steen.

"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
QuestionDeclare Byte Pin
Member 216100428-Sep-05 22:36
Member 216100428-Sep-05 22:36 
AnswerRe: Declare Byte Pin
kakan28-Sep-05 22:47
professionalkakan28-Sep-05 22:47 
GeneralRe: Declare Byte Pin
Member 216100428-Sep-05 23:20
Member 216100428-Sep-05 23:20 
GeneralRe: Declare Byte Pin
kakan28-Sep-05 23:29
professionalkakan28-Sep-05 23:29 
GeneralRe: Declare Byte Pin
toxcct28-Sep-05 23:38
toxcct28-Sep-05 23:38 
GeneralRe: Declare Byte Pin
kakan29-Sep-05 0:39
professionalkakan29-Sep-05 0:39 
GeneralRe: Declare Byte Pin
toxcct28-Sep-05 23:28
toxcct28-Sep-05 23:28 
AnswerRe: Declare Byte Pin
toxcct28-Sep-05 22:52
toxcct28-Sep-05 22:52 
AnswerRe: Declare Byte Pin
vikas amin28-Sep-05 23:05
vikas amin28-Sep-05 23:05 
QuestionCompiler Error C2504 please help Pin
WernerPos28-Sep-05 22:01
WernerPos28-Sep-05 22:01 
AnswerRe: Compiler Error C2504 please help Pin
Cedric Moonen28-Sep-05 22:07
Cedric Moonen28-Sep-05 22:07 
GeneralRe: Compiler Error C2504 please help Pin
WernerP28-Sep-05 22:38
WernerP28-Sep-05 22:38 
GeneralRe: Compiler Error C2504 please help Pin
WernerP28-Sep-05 22:46
WernerP28-Sep-05 22:46 
GeneralRe: Compiler Error C2504 please help Pin
WernerP29-Sep-05 1:42
WernerP29-Sep-05 1:42 
QuestionHow to get voice data Pin
pakFari28-Sep-05 21:14
pakFari28-Sep-05 21:14 
AnswerRe: How to get voice data Pin
kakan28-Sep-05 21:55
professionalkakan28-Sep-05 21:55 
GeneralRe: How to get voice data Pin
pakFari29-Sep-05 7:41
pakFari29-Sep-05 7:41 

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.