Hei!
Jeg har en del problemer med virtuelle funksjoner. Vi tar for oss x.cpp:
Ønsket output:
Problemet er at under kompilering av denne koden, får jeg feilmelding fra gcc:
Hvordan kan jeg få disse klassene til å virke sammen?
Jeg har en del problemer med virtuelle funksjoner. Vi tar for oss x.cpp:
Kode
#include <stdio.h> class A { public: virtual int a() = 0; int b() { return 1; } }; class B { public: int a() { return 0; }; }; class C : public A, public B { }; int main() { C c; printf("%d, %d\n", c.a(), c.b()); }
Kode
0, 1
Kode
x.cpp: In function ‘int main()’: x.cpp:22: error: cannot declare variable ‘c’ to be of abstract type ‘C’ x.cpp:17: note: because the following virtual functions are pure within ‘C’: x.cpp:6: note: virtual int A::a() x.cpp:23: error: request for member ‘a’ is ambiguous x.cpp:13: error: candidates are: int B::a() x.cpp:6: error: virtual int A::a()