我下面的Apache節儉教程:阿帕奇節儉和CPP代碼生成
https://svn.apache.org/repos/asf/thrift/attic/branches/0.9.x/tutorial/tutorial.thrift
它使用以下shared.thrift:
https://svn.apache.org/repos/asf/thrift/attic/branches/0.9.x/tutorial/shared.thrift
我生成所需的CPP源文件通過:
thrift --gen cpp shared.thrift
thrift --gen cpp tutorial.thrift
它給我的cpp文件列表,並在其中的一個我看到以下內容:
class CalculatorHandler : virtual public CalculatorIf {
... }
其中
class CalculatorIf : virtual public ::shared::SharedServiceIf {
... }
和
這不是編譯由於事實上,virtual void getStruct
是純虛擬的課程,但它的定義如下:
class SharedServiceHandler : virtual public SharedServiceIf {
void getStruct(SharedStruct& _return, const int32_t key) {
// Your implementation goes here
printf("getStruct\n");
}
}
這是編譯錯誤:
Calculator_server.skeleton.cpp:49:63: error: cannot allocate an object of abstract type 'CalculatorHandler'
shared_ptr<CalculatorHandler> handler(new CalculatorHandler());
^
Calculator_server.skeleton.cpp:19:7: note: because the following virtual functions are pure within 'CalculatorHandler':
class CalculatorHandler : virtual public CalculatorIf {
^
In file included from Calculator.h:12:0,
from Calculator_server.skeleton.cpp:4:
SharedService.h:18:16: note: virtual void shared::SharedServiceIf::getStruct(shared::SharedStruct&, int32_t)
virtual void getStruct(SharedStruct& _return, const int32_t key) = 0;
於是問題來了:這是節儉的CPP代碼生成一個錯誤,它無法正確識別所需的基類或我錯在做什麼?
(這個問題是不是約,因爲這是全部由儉生成的代碼固定C++編譯錯誤。這個問題是關於節儉)
這看起來非常像(尚未固定的)[THRIFT-1372](https://issues.apache.org/jira/browse/THRIFT-1372)給我。 – JensG
很難說沒有看到所有的代碼,但看起來雖然getStruct是在'SharedServiceHandler'中定義的,你實際上是從'SharedServiceIf'繼承的,它是一個純虛擬的(即一個接口)。所以看起來你可能需要實現它。道歉,如果這不現場,但很難說沒有所有的代碼。 – systemcpro