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

C / C++ / MFC

 
Questionmatrix's reverse Pin
atena8-Feb-08 4:16
atena8-Feb-08 4:16 
GeneralRe: matrix's reverse Pin
led mike8-Feb-08 4:20
led mike8-Feb-08 4:20 
GeneralRe: matrix's reverse Pin
CPallini8-Feb-08 4:31
mveCPallini8-Feb-08 4:31 
GeneralRe: matrix's reverse Pin
Iain Clarke, Warrior Programmer8-Feb-08 4:34
Iain Clarke, Warrior Programmer8-Feb-08 4:34 
GeneralCreate an Elevated Process & Wait for the process to complete in Vista Pin
vikrant kpr8-Feb-08 3:15
vikrant kpr8-Feb-08 3:15 
GeneralRe: Create an Elevated Process & Wait for the process to complete in Vista Pin
Iain Clarke, Warrior Programmer8-Feb-08 4:39
Iain Clarke, Warrior Programmer8-Feb-08 4:39 
GeneralRe: Create an Elevated Process & Wait for the process to complete in Vista Pin
Mark Salsbery8-Feb-08 11:56
Mark Salsbery8-Feb-08 11:56 
Generalstrange virtual function output Pin
George_George8-Feb-08 2:24
George_George8-Feb-08 2:24 
Hello everyone,


Why in the below code,

pb->foo();

will output Final other than output Base? I have tested that the output is Final.

My question is
1. pb points Final instance, and the foo in Final is not virtual method;
2. if function is virtual, we should invoke the foo based on the type of instance pointed to, if not virtual, we should invoke the foo based on the type which is the pionter type;
3. since foo in Final is not final, so the output should be invoking the foo based on the type of pointer (which is Base), then the output should be Base?


class Base {
public:
    virtual int foo() {cout << "Base" << endl; return 0;}
};
 
class Derived: public Base
{
public:
    int foo() {cout << "Derived" << endl;return 0;}
};
 
class Final: public Derived{
public:
  int foo() {cout << "Final" << endl;return 0;}
};
 
int main()
{
    Final f;
    Base* pb = reinterpret_cast<base*>(&f);
    pb->foo();
 
    return 0;
}
</base*>



regards,
George
GeneralRe: strange virtual function output Pin
David Crow8-Feb-08 2:44
David Crow8-Feb-08 2:44 
GeneralRe: strange virtual function output Pin
George_George8-Feb-08 21:35
George_George8-Feb-08 21:35 
GeneralRe: strange virtual function output Pin
CPallini8-Feb-08 2:48
mveCPallini8-Feb-08 2:48 
GeneralRe: strange virtual function output Pin
George_George8-Feb-08 21:36
George_George8-Feb-08 21:36 
GeneralRe: strange virtual function output Pin
BadKarma8-Feb-08 2:55
BadKarma8-Feb-08 2:55 
GeneralRe: strange virtual function output Pin
George_George8-Feb-08 21:39
George_George8-Feb-08 21:39 
GeneralRe: strange virtual function output Pin
Rajkumar R8-Feb-08 3:40
Rajkumar R8-Feb-08 3:40 
GeneralRe: strange virtual function output Pin
George_George8-Feb-08 21:47
George_George8-Feb-08 21:47 
GeneralRe: strange virtual function output Pin
Rajkumar R8-Feb-08 23:01
Rajkumar R8-Feb-08 23:01 
GeneralRe: strange virtual function output Pin
George_George9-Feb-08 20:57
George_George9-Feb-08 20:57 
GeneralRe: strange virtual function output Pin
Rajkumar R10-Feb-08 22:29
Rajkumar R10-Feb-08 22:29 
GeneralRe: strange virtual function output Pin
George_George10-Feb-08 22:33
George_George10-Feb-08 22:33 
GeneralRe: strange virtual function output Pin
Rajkumar R10-Feb-08 23:04
Rajkumar R10-Feb-08 23:04 
GeneralRe: strange virtual function output Pin
George_George11-Feb-08 22:03
George_George11-Feb-08 22:03 
GeneralEmbedding HTML code into VC Pin
Gita.Bairavi8-Feb-08 1:37
Gita.Bairavi8-Feb-08 1:37 
GeneralRe: Embedding HTML code into VC Pin
Rajkumar R8-Feb-08 3:56
Rajkumar R8-Feb-08 3:56 
GeneralRe: Embedding HTML code into VC Pin
Hamid_RT10-Feb-08 21:28
Hamid_RT10-Feb-08 21:28 

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.