我尝试实现一些接口及其子接口。这是我的想法:
Interface
/ \
Interface2 InterfaceDefination
| /
Interface2Defination
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
Interface
/ \
Interface2 InterfaceDefination
| /
Interface2Defination
Run Code Online (Sandbox Code Playgroud)
我的预期输出是:
method1 from InterfaceDefination
method2 from Interface2Defination
print from Interface2Defination
Run Code Online (Sandbox Code Playgroud)
但意外地我收到了这些错误:
main.cpp:33:24: error: variable type 'Interface2Defination' is an abstract class
Interface2Defination c;
^
main.cpp:5:16: note: unimplemented pure virtual method 'method1' in 'Interface2Defination'
virtual void method1() = 0;
^
1 error generated.
make: *** [<builtin>: main.o] Error 1
exit status 2
Run Code Online (Sandbox Code Playgroud)
https://godbolt.org/z/9ncoGfn4P
在这种情况下,错误意味着using关键字没有使方法method1在 class 中可用Interface2Defination。我应该用它做什么?