Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/137.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache节约C++ TyPufF问题_C++_Thrift_Thrift Protocol - Fatal编程技术网

Apache节约C++ TyPufF问题

Apache节约C++ TyPufF问题,c++,thrift,thrift-protocol,C++,Thrift,Thrift Protocol,我正在尝试创建一个简单的储蓄服务器,将两个数字相乘 我写了这样的旧文件: namespace cpp tutorial typedef i32 int service MultiplicationService { int multiply(1:int n1, 2:int n2), } #include "MultiplicationService.h" #include <thrift/protocol/TBinaryProtocol.h> #include &l

我正在尝试创建一个简单的储蓄服务器,将两个数字相乘

我写了这样的旧文件:

namespace cpp tutorial

typedef i32 int

service MultiplicationService
{

    int multiply(1:int n1, 2:int n2),

}
#include "MultiplicationService.h"
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/server/TSimpleServer.h>
#include <thrift/transport/TServerSocket.h>
#include <thrift/transport/TBufferTransports.h>

using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::server;

using boost::shared_ptr;

using namespace  ::tutorial;

class MultiplicationServiceHandler : virtual public MultiplicationServiceIf {
 public:
  MultiplicationServiceHandler() {
    // Your initialization goes here
  }

  int multiply(const int n1, const int n2) {
    return n1 * n2;
  }

};

int main(int argc, char **argv) {
  int port = 9090;
  shared_ptr<MultiplicationServiceHandler> handler(new MultiplicationServiceHandler());
  shared_ptr<TProcessor> processor(new MultiplicationServiceProcessor(handler));
  shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
  shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
  shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());

  TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
  server.serve();
  return 0;
}
/**
 * Autogenerated by Thrift Compiler (0.9.2)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
#ifndef multi_TYPES_H
#define multi_TYPES_H

#include <iosfwd>

#include <thrift/Thrift.h>
#include <thrift/TApplicationException.h>
#include <thrift/protocol/TProtocol.h>
#include <thrift/transport/TTransport.h>

#include <thrift/cxxfunctional.h>


namespace tutorial {

typedef int32_t int;

} // namespace

#endif
在那之后,我运行了thrift-gen cpp multi.thrift

我将骨架文件重命名为MultiplicationServer.cpp,如下所示:

namespace cpp tutorial

typedef i32 int

service MultiplicationService
{

    int multiply(1:int n1, 2:int n2),

}
#include "MultiplicationService.h"
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/server/TSimpleServer.h>
#include <thrift/transport/TServerSocket.h>
#include <thrift/transport/TBufferTransports.h>

using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::server;

using boost::shared_ptr;

using namespace  ::tutorial;

class MultiplicationServiceHandler : virtual public MultiplicationServiceIf {
 public:
  MultiplicationServiceHandler() {
    // Your initialization goes here
  }

  int multiply(const int n1, const int n2) {
    return n1 * n2;
  }

};

int main(int argc, char **argv) {
  int port = 9090;
  shared_ptr<MultiplicationServiceHandler> handler(new MultiplicationServiceHandler());
  shared_ptr<TProcessor> processor(new MultiplicationServiceProcessor(handler));
  shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
  shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
  shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());

  TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
  server.serve();
  return 0;
}
/**
 * Autogenerated by Thrift Compiler (0.9.2)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
#ifndef multi_TYPES_H
#define multi_TYPES_H

#include <iosfwd>

#include <thrift/Thrift.h>
#include <thrift/TApplicationException.h>
#include <thrift/protocol/TProtocol.h>
#include <thrift/transport/TTransport.h>

#include <thrift/cxxfunctional.h>


namespace tutorial {

typedef int32_t int;

} // namespace

#endif
我试着删除那一行,但后来我得到了很多未定义的错误引用


我做错了什么?

您尝试将Thrift i32类型定义为int,这实际上会产生名称冲突

因此,解决方案是不这样做:

namespace cpp another_tutorial

// typedef i32 int - don't try this at home

service MultiplicationService
{
    i32 multiply( 1 : i32 n1, 2 : i32 n2)
}

哪一行导致问题?typedef?是的,在typedef行。