Compiler errors 编译错误g++;5.2 Windows 10出主意

Compiler errors 编译错误g++;5.2 Windows 10出主意,compiler-errors,g++,Compiler Errors,G++,我有这些编译错误,我真的看不出我的代码有什么问题,请帮助我 g++主要抱怨某些行没有使用“->”操作符,但我正在使用它,所以这个错误对我来说似乎很奇怪 g++ tests/client.cpp src/jsonrpc/transport/PipeClient.cpp -o client --std=c++11 -I ./include -lstdc++ -lboost_thread-mgw52-mt-1_59 -lboost_system-mgw52-mt-1_59 -D_WIN32_WINNT

我有这些编译错误,我真的看不出我的代码有什么问题,请帮助我

g++主要抱怨某些行没有使用“->”操作符,但我正在使用它,所以这个错误对我来说似乎很奇怪

g++ tests/client.cpp src/jsonrpc/transport/PipeClient.cpp -o client --std=c++11 -I ./include -lstdc++ -lboost_thread-mgw52-mt-1_59 -lboost_system-mgw52-mt-1_59 -D_WIN32_WINNT=0x0600
include/jsonrpc/Client.h: In instantiation of 'bool jsonrpc::Client<ServerSocketType, ClientSocketType>::connect(std::__cxx11::string) [with ServerSocketType = jsonrpc::PipeServer; ClientSocketType = jsonrpc::PipeClient; std::__cxx11::string = std::__cxx11::basic_string<char>]':
tests/client.cpp:13:42:   required from here
include/jsonrpc/Client.h:29:48: error: request for member 'connect' in '((jsonrpc::Client<jsonrpc::PipeServer, jsonrpc::PipeClient>*)this)->jsonrpc::Client<jsonrpc::PipeServer, jsonrpc::PipeClient>::m_socket', which is of pointer type 'jsonrpc::PipeClient*' (maybe you meant to use '->' ?)
include/jsonrpc/Client.h: In instantiation of 'bool jsonrpc::Client<ServerSocketType, ClientSocketType>::sendRequest(jsonrpc::Request*) [with ServerSocketType = jsonrpc::PipeServer; ClientSocketType = jsonrpc::PipeClient]':
tests/client.cpp:19:32:   required from here
include/jsonrpc/Client.h:52:34: error: invalid initialization of non-const reference of type 'std::__cxx11::string& {aka std::__cxx11::basic_string<char>&}' from an rvalue of type 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}'
include/jsonrpc/Client.h:85:18: note:   initializing argument 1 of 'bool jsonrpc::Client<ServerSocketType, ClientSocketType>::sendPacket(std::__cxx11::string&) [with ServerSocketType = jsonrpc::PipeServer; ClientSocketType = jsonrpc::PipeClient; std::__cxx11::string = std::__cxx11::basic_string<char>]'
                         packet.append(buffer, bytesRead);
                  ^
include/jsonrpc/Client.h: In instantiation of 'void jsonrpc::Client<ServerSocketType, ClientSocketType>::disconnect() [with ServerSocketType = jsonrpc::PipeServer; ClientSocketType = jsonrpc::PipeClient]':
include/jsonrpc/Client.h:24:27:   required from 'jsonrpc::Client<ServerSocketType, ClientSocketType>::~Client() [with ServerSocketType = jsonrpc::PipeServer; ClientSocketType = jsonrpc::PipeClient]'
tests/client.cpp:11:36:   required from here
include/jsonrpc/Client.h:34:17: error: request for member 'disconnect' in '((jsonrpc::Client<jsonrpc::PipeServer, jsonrpc::PipeClient>*)this)->jsonrpc::Client<jsonrpc::PipeServer, jsonrpc::PipeClient>::m_socket', which is of pointer type 'jsonrpc::PipeClient*' (maybe you meant to use '->' ?)
In file included from ./include/jsonrpc/Request.h:4:0,
                 from include/jsonrpc/Client.h:6:
./include/jsonrpc/Message.h: In instantiation of 'static std::__cxx11::string jsonrpc::Message::toJson(const std::vector<MessageType*>&) [with MessageType = jsonrpc::Request; std::__cxx11::string = std::__cxx11::basic_string<char>]':
include/jsonrpc/Client.h:52:59:   required from 'bool jsonrpc::Client<ServerSocketType, ClientSocketType>::sendRequest(jsonrpc::Request*) [with ServerSocketType = jsonrpc::PipeServer; ClientSocketType = jsonrpc::PipeClient]'
tests/client.cpp:19:32:   required from here
./include/jsonrpc/Message.h:57:21: error: no matching function for call to 'rapidjson::GenericDocument<rapidjson::UTF8<> >::Swap(jsonrpc::Request* const&)'
In file included from ./include/jsonrpc/Message.h:4:0,
                 from ./include/jsonrpc/Request.h:4,
                 from include/jsonrpc/Client.h:6:
D:/usr/msys2/mingw64/include/rapidjson/document.h:655:19: note: candidate: rapidjson::GenericValue<Encoding, Allocator>& rapidjson::GenericValue<Encoding, Allocator>::Swap(rapidjson::GenericValue<Encoding, Allocator>&) [with Encoding = rapidjson::UTF8<>; Allocator = rapidjson::MemoryPoolAllocator<>]
     GenericValue& Swap(GenericValue& other) RAPIDJSON_NOEXCEPT {
                   ^
D:/usr/msys2/mingw64/include/rapidjson/document.h:655:19: note:   no known conversion for argument 1 from 'const value_type {aka jsonrpc::Request* const}' to 'rapidjson::GenericValue<rapidjson::UTF8<> >&'
g++tests/client.cpp src/jsonrpc/transport/PipeClient.cpp-o client--std=c++11-I./include-lstdc++-lboost_thread-mgw52-mt-1_59-lboost_system-mgw52-mt-1_59-D_WIN32_=0x0600
包括/jsonrpc/Client.h:在“booljsonrpc::Client::connect(std::_xx11::string)[与ServerSocketType=jsonrpc::PipeServer;ClientSocketType=jsonrpc::PipeClient;std:ucxx11::string=std:_cxx11::basic_string]”的实例化中:
测试/客户端。cpp:13:42:此处需要
include/jsonrpc/Client.h:29:48:错误:在((jsonrpc::Client*)this)->jsonrpc::Client::m_socket'中请求成员“connect”,它是指针类型“jsonrpc::PipeClient*”(可能您打算使用“->”?)
在“bool jsonrpc::Client::sendRequest(jsonrpc::Request*)[with ServerSocketType=jsonrpc::PipeServer;ClientSocketType=jsonrpc::PipeClient]”的实例化中包括/jsonrpc/Client.h:
测试/客户端。cpp:19:32:此处为必填项
include/jsonrpc/Client.h:52:34:错误:从“std::”类型的右值中初始化类型为“std::”的非常量引用无效。{aka std:::”的非常量引用无效。}
include/jsonrpc/Client.h:85:18:注意:初始化'booljsonrpc::Client::sendPacket(std::_xx11::string&')[with-ServerSocketType=jsonrpc::PipeServer;ClientSocketType=jsonrpc::PipeClient;std:_xx11::string=std:u xx11::basic_string]”的参数1
packet.append(缓冲区,字节读取);
^
在“void jsonrpc::Client::disconnect()[with ServerSocketType=jsonrpc::PipeServer;ClientSocketType=jsonrpc::PipeClient]”的实例化中包括/jsonrpc/Client.h::
include/jsonrpc/Client.h:24:27:在“jsonrpc::Client::~Client()[与ServerSocketType=jsonrpc::PipeServer;ClientSocketType=jsonrpc::PipeClient一起]”中是必需的
测试/客户。cpp:11:36:此处需要
include/jsonrpc/Client.h:34:17:错误:在“((jsonrpc::Client*)this)->jsonrpc::Client::m_socket”中请求成员“disconnect”(可能您打算使用“->”?)
在包含自./include/jsonrpc/Request.h:4:0的文件中,
来自include/jsonrpc/Client.h:6:
./include/jsonrpc/Message.h:在“static std::uu cxx11::string jsonrpc::Message::toJson(const std::vector&)[with MessageType=jsonrpc::Request;std:uu cxx11::string=std:u cxx11::basic_string]”的实例化中:
include/jsonrpc/Client.h:52:59:从'bool jsonrpc::Client::sendRequest(jsonrpc::Request*)[与ServerSocketType=jsonrpc::PipeServer;ClientSocketType=jsonrpc::PipeClient]一起]中需要
测试/客户端。cpp:19:32:此处为必填项
./include/jsonrpc/Message.h:57:21:错误:对“rapidjson::GenericDocument::Swap(jsonrpc::Request*const&)”的调用没有匹配的函数
在包含自./include/jsonrpc/Message.h:4:0的文件中,
from./include/jsonrpc/Request.h:4,
来自include/jsonrpc/Client.h:6:
D:/usr/msys2/mingw64/include/rapidjson/document.h:655:19:注:候选:rapidjson::GenericValue&rapidjson::GenericValue::Swap(rapidjson::GenericValue&)[带Encoding=rapidjson::UTF8;分配器=rapidjson::memorypooldocator]
一般价值和交换(一般价值和其他)快速{
^
D:/usr/msys2/mingw64/include/rapidjson/document.h:655:19:注意:参数1从'const value_type{aka jsonrpc::Request*const}'到'rapidjson::GenericValue&'没有已知的转换
测试/client.cpp

#include "jsonrpc/Client.h"
#include "jsonrpc/transport/PipeServer.h"
#include "jsonrpc/transport/PipeClient.h"

#include <iostream>

using namespace jsonrpc;

int main(int argc, char * argv[])
{
    Client<PipeServer, PipeClient> client;

    client.connect("\\\\.\\pipe\\jsonrpc");

    typedef Request::ValueType Value;

    Request request(Value("_1").Move(), Value("test").Move(), Value(rapidjson::kArrayType).Move());

    client.sendRequest(&request);

    std::vector<Response *> responses;
    client.recvResponses(responses);

    std::cout << responses[0]->toJson() << std::endl;
}
#包括“jsonrpc/Client.h”
#包括“jsonrpc/transport/PipeServer.h”
#包括“jsonrpc/transport/PipeClient.h”
#包括
使用名称空间jsonrpc;
int main(int argc,char*argv[])
{
客户;
client.connect(“\\.\\pipe\\jsonrpc”);
typedef请求::ValueType值;
请求请求(Value(“_1”).Move()、Value(“test”).Move()、Value(rapidjson::kArrayType).Move());
client.sendRequest(&request);
病媒反应;
客户回复(回复);
std::couttojson()连接(地址);
}
无效断开连接()
{
m_插座->断开连接();
}
bool RECVRRESPONSES(标准::向量和响应)
{
std::字符串包;
如果(!this->recvPacket(数据包)){
返回false;
}
responses=Response::parseJson(数据包);
返回true;
}
bool sendRequest(请求*请求)
{
返回sendRequests(std::vector(1,请求));
}
bool sendRequests(std::vector和requests)
{
std::string packet=Request::toJson(请求);
返回发送包(packet);
}
私人:
ClientSocketType*m_插座;
服务器类型*m_服务器;
客户端(ClientSocketType*套接字,ServerType*服务器):m_套接字(套接字),m_服务器(服务器){}
bool recvPacket(标准::字符串和数据包)
{
char*buffer=新字符[JSONRPC_READ_buffer_LENGTH];
packet.empty();
做{
ssize\u t bytesRead=m\u socket->read(buffer,JSONRPC\u read\u buffer\u LENGTH);
如果(字节读取>0){
packet.append(缓冲区,字节读取);
}否则{
打破
}
}while(packet[packet.length()-1]!='\n');
返回packet.size()>0;
}
boolsendpacket(标准::字符串和数据包)
{
数据包+=“\n”;
size_t length=packet.length();
尺寸偏差=0;
趁
#ifndef JSONRPC_CLIENT_H
#define JSONRPC_CLIENT_H

#include "jsonrpc/base.h"
#include "jsonrpc/Server.h"
#include "jsonrpc/Request.h"
#include "jsonrpc/Response.h"

#include <string>
#include <vector>
#include <boost/bind.hpp>
#include <boost/thread.hpp>

namespace jsonrpc
{
    template <typename ServerSocketType, typename ClientSocketType>
    class Server;

    template <typename ServerSocketType, typename ClientSocketType>
    class Client
    {
        typedef Server<ServerSocketType, ClientSocketType> ServerType;
        typedef Client<ServerSocketType, ClientSocketType> ClientType;

        friend ServerType;

        public:
            Client() : m_socket(new ClientSocketType()), m_server(NULL) {}

            ~Client()
            {
                disconnect();
            }

            bool connect(const std::string & address)
            {
                return m_socket->connect(address);
            }

            void disconnect()
            {
                m_socket->disconnect();
            }

            bool recvResponses(std::vector<Response *> & responses)
            {
                std::string packet;

                if (!this->recvPacket(packet)) {
                    return false;
                }

                responses = Response::parseJson<Response>(packet);

                return true;
            }

            bool sendRequest(Request * request)
            {
                return sendRequests(std::vector<Request *>(1, request));
            }

            bool sendRequests(std::vector<Request *> & requests)
            {
                std::string packet = Request::toJson<Request>(requests);
                return sendPacket(packet);
            }

        private:
            ClientSocketType * m_socket;
            ServerType * m_server;

            Client(ClientSocketType * socket, ServerType * server) : m_socket(socket), m_server(server) {}

            bool recvPacket(std::string & packet)
            {
                char * buffer = new char[JSONRPC_READ_BUFFER_LENGTH];

                packet.empty();

                do {
                    ssize_t bytesRead = m_socket->read(buffer, JSONRPC_READ_BUFFER_LENGTH);

                    if (bytesRead > 0) {
                        packet.append(buffer, bytesRead);
                    } else {
                        break;
                    }
                } while (packet[packet.length() - 1] != '\n');

                return packet.size() > 0;
            }

            bool sendPacket(std::string & packet)
            {
                packet += "\n";

                size_t length = packet.length();
                size_t offset = 0;

                while (offset < length) {
                    ssize_t bytesWritten = m_socket->write(packet.c_str() + offset, std::min<size_t>(JSONRPC_WRITE_BUFFER_LENGTH, length - offset));

                    if (bytesWritten > 0) {
                        offset += bytesWritten;
                    } else {
                        break;
                    }
                }

                m_socket->flush();
            }

            void start()
            {
                boost::thread thread(boost::bind(ClientType::run, this));
            }

            void run()
            {
                std::string packet;

                while (recvPacket(packet)) {
                    handlePacket(packet);
                }
            }

            void handlePacket(std::string packet)
            {
                typedef Request::ValueType Value;

                std::vector<Request *> requests = Request::parseJson<Request>(packet);
                std::vector<Response *> responses;

                for (Request * request : requests) {
                    Response * response;

                    if (request->IsNull()) {
                        response = new Response(Value().Move(), Value(-32700).Move(), Value("Parse error").Move());
                    } else if (request->isValid()) {
                        response = m_server->handleRequest(request);
                    } else if (request->hasValidId()) {
                        response = new Response(Value(request->getId(), request->GetAllocator).Move(), Value(-32600).Move(), Value("Invalid request").Move());
                    } else {
                        response = new Response(Value().Move(), Value(-32600).Move(), Value("Invalid request").Move());
                    }

                    delete request;
                    responses.push_back(response);
                }

                sendPacket(Response::toJson<Response>(responses).c_str());
            }
    };
}

#endif // JSONRPC_CLIENT_H
#ifndef JSONRPC_MESSAGE_H
#define JSONRPC_MESSAGE_H

#include <vector>

#include <rapidjson/document.h>
#include <rapidjson/writer.h>

namespace jsonrpc
{
    class Message : public rapidjson::Document
    {
        typedef rapidjson::StringBuffer StringBuffer;
        typedef rapidjson::Writer<StringBuffer> StringWriter;

        public:
            const ValueType & getId() const
            {
                return operator[]("id");
            }

            const Ch * toJson()
            {
                StringBuffer buffer;
                StringWriter writer(buffer);

                Accept(writer);

                return buffer.GetString();
            }

            template <typename MessageType>
            static std::vector<MessageType *> parseJson(const std::string & json)
            {
                rapidjson::Document document;
                document.Parse(json.c_str());

                std::vector<MessageType *> messages;

                if (document.IsArray()) {
                    for (rapidjson::SizeType i = 0; i < document.Size(); ++i) {
                        messages.push_back(new MessageType(document[i]));
                    }
                }
                else {
                    messages.push_back(new MessageType(document));
                } 

                return messages;
            }

            template <typename MessageType>
            static std::string toJson(std::vector<MessageType *> & messages)
            {
                rapidjson::Document document;
                size_t nbMessages = messages.size();

                if (nbMessages == 1) {
                    document.Swap(messages[0]->Move());
                }
                else if (nbMessages > 1) {
                    document.SetArray();

                    for (MessageType * message : messages) {
                        document.PushBack(*message, document.GetAllocator());
                    }
                }
                else {
                    return "";
                }

                StringBuffer buffer;
                StringWriter writer(buffer);

                document.Accept(writer);

                return buffer.GetString();
            }
    };
}

#endif // JSONRPC_MESSAGE_H