Hi All,

          In the code below, even though pD is actually pointing to a base
class object, how is the print function being successfully called?

#include<iostream>

class base
{
public:
    int BVal;
    base()
    {
        BVal = 100;
    }
};

class derived : public base
{
public:
    derived()
    {
        DVal = 500;
    }
    void print()
    {
        std::cout<<"\nBVal ="<<BVal<<std::endl<<"DVal = "<<DVal<<std::endl;
    }
    int DVal;
};

int main()
{
    base B;
    derived D;
    derived *pD;
    *pD = static_cast<derived*>(&B);*
    *pD->print();*
    return 0;
}

-- 
Regards,
Shachindra A C

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to