HI,
   I have a small query. In virtual inheritence , the function wil be called 
basing on the object we assign for the base class pointer. But how variable 
address will be resolved. I observed that even variable are getting resolved 
basing on the object we assign (like function). But I think there is no virtual 
concept for variables. only for functions.

#include<stdio.h>
#include<conio.h>


class base
{
public:
    int var1 , var2;
    base(int a,int b)
    {
        var1=a;
        var2=b;
        printf("\n I am in base. var1 = %d , var2 = %d",var1 , var2);
    };
    virtual void show()
    {
        printf("\n I am in base class virtual method . show. My var1 value is 
%d , var 2 value is %d",var1 , var2);
    };
    void disp()
    {
        printf("\n I am in  base class non virtual method. disp. My var1 is %d 
, var2 is %d",var1 , var2);
    };
};
class derived:public base
{
public:
    int var1 , var2;
    derived(int a,int b):base(a+1,b+1)
    {
        var1=a;
        var2=b;
        printf("\n I m in derived class. My var1 is %d , var 2 is %d ",var1 , 
var2);
    };
    void show()
    {
        printf("\n I am in defrived class virtual method . show. My var1 value 
is %d , var 2 value is %d",var1 , var2);

    }
    void disp()
    {
        printf("\n I am in  derived class non virtual method. disp. My var1 is 
%d , var2 is %d",var1 , var2);
    }
};
void main()
{
    base *x = new derived(1,2);
    
    base *y = new base(10,20);
    x->show();  /// show here displaying 1,2 instead of base variable values. 
But I think there is no virtual concept here. so I think it should display base 
class variable values. please clarify my confusion.
    printf("\n \n ]\n");
    y->show();

}


Thx,
--Gopi



      Explore and discover exciting holidays and getaways with Yahoo! India 
Travel http://in.travel.yahoo.com/

[Non-text portions of this message have been removed]

Reply via email to