jeudi 26 février 2015

Overloaded final function in derived class

How can I use final overloaded function from derived class?

Compiler says 'no matching function for call to 'B::foo()''.



class A
{
public:
virtual void foo() final
{
std::cout << "foo";
}
virtual void foo(int b) = 0;
};

class B : public A
{
public:
void foo(int b) override
{
std::cout << b;
}
};

//Somewhere
B* b = new B;
b->foo(); //Error


But it works without overloading.



class A
{
public:
virtual void foo() final
{
std::cout << "foo";
}
};

class B : public A
{
};

//Somewhere
B* b = new B;
b->foo(); //Works!

Aucun commentaire:

Enregistrer un commentaire