I have a program
#include <iostream>
struct A {
virtual char f() = 0;
};
struct B {
virtual char f() = 0;
};
struct Derived : A, B {
public:
char A::f() override { return CA; }
char B::f() override { return CB; }
const char CA = 'A';
const char CB = 'B';
};
int main(int argc, char** argv)
{
Derived d;
A& a = d;
printf("%c", a.f());
return 0;
}
It works fine. But when I define A::f outside of the declaration, I have an error.
struct Derived : A, B {
public:
char A::f() override;
char B::f() override { return CB; }
const char CA = 'A';
const char CB = 'B';
};
char Derived::A::f() { return CA; } //error C2509: 'f': member function not declared in 'Derived'
My question is how to refer correctly to A::f in the definition?
#include <iostream>and then not use anything from it but instead use stuff declared in<cstdio>?A::fin the definition? If the functions need to be independent, the most expedient solution is to either change the name ofA::f, or change the name ofB::f.