2011-04-18 25 views
3

如果我們重新定義數據成員,那麼類的實現會發生什麼? 例如,假設我們有:如果重新定義數據成員,則實現類

class foo { 
public: 
    int a; 
    char *b; 
}; 
... 
class bar : public foo { 
public: 
    float c; 
    int b; 
}; 

是否酒吧對象表示包含一個B場還是兩個?如果兩個,他們都可以訪問,或只有一個?在什麼情況下?

回答

5

它包含兩個,但其中一人被叫做foo :: B

int main() { 
    bar x; 
    x.b = 0; // access bar::b 
    x.foo::b = 0; // access foo::b 
} 
相關問題