1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

data member of base class but not of derive class..why?

Discussion in 'C++' started by zubairjam, Oct 3, 2010.

  1. zubairjam

    zubairjam New Member

    Joined:
    Oct 3, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    int main()
    {
        D d;
        cout<<"size of d: "<<sizeof(d)<<endl;//8
        cout<<"i: "<<d.i<<endl;//error
        return 0;
    }
    
    error: i is not member of D.
    but D is derived from B...i is in public part then why this
    error :thinking::thinking::thinking:
     
    Last edited by a moderator: Oct 3, 2010
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    How can we debug code that you don't post?

    You're right though: it SHOULD work. So we need to see the code to find the problem.
    Try to cut B and D down to the least possible (ideally just the i definition).
     
    shabbir likes this.

Share This Page