3 回答

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超11個(gè)贊
C ++語法如下:
class Bar : public Foo {
// ...
void printStuff() {
Foo::printStuff(); // calls base class' function
}
};

TA貢獻(xiàn)1868條經(jīng)驗(yàn) 獲得超4個(gè)贊
是,
class Bar : public Foo
{
...
void printStuff()
{
Foo::printStuff();
}
};
它與superJava中的相同,不同之處在于它允許您在具有多個(gè)繼承時(shí)從不同的基礎(chǔ)調(diào)用實(shí)現(xiàn)。
class Foo {
public:
virtual void foo() {
...
}
};
class Baz {
public:
virtual void foo() {
...
}
};
class Bar : public Foo, public Baz {
public:
virtual void foo() {
// Choose one, or even call both if you need to.
Foo::foo();
Baz::foo();
}
};

TA貢獻(xiàn)1854條經(jīng)驗(yàn) 獲得超8個(gè)贊
有時(shí),當(dāng)您不在派生函數(shù)中時(shí),您需要調(diào)用基類的實(shí)現(xiàn)...它仍然有效:
struct Base
{
virtual int Foo()
{
return -1;
}
};
struct Derived : public Base
{
virtual int Foo()
{
return -2;
}
};
int main(int argc, char* argv[])
{
Base *x = new Derived;
ASSERT(-2 == x->Foo());
//syntax is trippy but it works
ASSERT(-1 == x->Base::Foo());
return 0;
}
- 3 回答
- 0 關(guān)注
- 546 瀏覽
添加回答
舉報(bào)