base class , inheritate class sizeof()

Posted by user1279988 on Stack Overflow See other posts from Stack Overflow or by user1279988
Published on 2012-03-27T05:19:53Z Indexed on 2012/03/27 5:29 UTC
Read the original article Hit count: 153

Filed under:
|

why sizeof(X) is 4 and sizeof(Y) is 8?

and another question, in class X, only the int(i) count as sizeof() 4? member function does take any memory space?

Plz tell me, thanks!

class X {
    int i;
public:
    X() { i = 0; }
    void set(int ii) { i = ii; }
    int read() const { return i; }
    int permute() { return i = i * 47; }
};

class Y : public X {
    int i; // Different from X's i
public:
    Y() { i = 0; }
    int change() {
        i = permute(); // Different name call
        return i;
    }
    void set(int ii) {
        i = ii;
        X::set(ii); // Same-name function call
    }
};


    cout << "sizeof(X) = " << sizeof(X) << endl;
    cout << "sizeof(Y) = "

© Stack Overflow or respective owner

Related posts about c++

Related posts about class