vs2015 调用websocket,报错:C2752 ...多个部分专用化与模板参数列表匹配

如图,vs2015 调用websocket,报错。boost 和websocket 目录都已经包含。代码是从websocket的demo里copy的client代码。研究了一段时间,一直没有思路,求各位帮忙看看有什么解决的思路。

img


#include "stdafx.h"
#include <websocketpp/config/asio_no_tls_client.hpp>
#include <websocketpp/client.hpp>

#include <iostream>

typedef websocketpp::client<websocketpp::config::asio_client> client;

using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;

// pull out the type of messages sent by our config
typedef websocketpp::config::asio_client::message_type::ptr message_ptr;

// This message handler will be invoked once for each incoming message. It
// prints the message and then sends a copy of the message back to the server.
void on_message(client* c, websocketpp::connection_hdl hdl, message_ptr msg) {
    std::cout << "on_message called with hdl: " << hdl.lock().get()
        << " and message: " << msg->get_payload()
        << std::endl;


    websocketpp::lib::error_code ec;

    c->send(hdl, msg->get_payload(), msg->get_opcode(), ec);
    if (ec) {
        std::cout << "Echo failed because: " << ec.message() << std::endl;
    }
}

int main(int argc, char* argv[]) {
    // Create a client endpoint
    client c;

    std::string uri = "ws://localhost:9002";

    if (argc == 2) {
        uri = argv[1];
    }

    try {
        // Set logging to be pretty verbose (everything except message payloads)
        c.set_access_channels(websocketpp::log::alevel::all);
        c.clear_access_channels(websocketpp::log::alevel::frame_payload);

        // Initialize ASIO
        c.init_asio();

        // Register our message handler
        c.set_message_handler(bind(&on_message, &c, ::_1, ::_2));

        websocketpp::lib::error_code ec;
        client::connection_ptr con = c.get_connection(uri, ec);
        if (ec) {
            std::cout << "could not create connection because: " << ec.message() << std::endl;
            return 0;
        }

        // Note that connect here only requests a connection. No network messages are
        // exchanged until the event loop starts running in the next line.
        c.connect(con);

        // Start the ASIO io_service run loop
        // this will cause a single connection to be made to the server. c.run()
        // will exit when this connection is closed.
        c.run();
    }
    catch (websocketpp::exception const & e) {
        std::cout << e.what() << std::endl;
    }
}


不发代码?自己研究一下。
2893错误演示

#include<map>
using namespace std;
class MyClass {};

template<class T>
inline typename T::data_type

f(T const& p1, MyClass const& p2);

template<class T>
void bar(T const& p1) {
    MyClass r;
    f(p1,r);   // 这里出现C2893错误
}

int main() {
   map<int,int> m;
   bar(m);
}

2752错误演示

template<class T, class U>
struct A {};

template<class T, class U>
struct A<T*, U> {};

template<class T, class U>
struct A<T,U*> {};



int main() {
   A<char*,int*> a;   // C2752这里出现

   A<char*,int> a1;
   A<char,int*> a2;
   A<char,int> a3;
}

https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c2752?view=msvc-170
https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c2893?view=msvc-170

就是类型不匹配,
找到报错的代码行,检查一下出错的地方每一个函数参数的类型,对照一下函数声明看是否匹配,对照一下官网API手册看怎么使用。

不能直接拷贝吧,我们都是下载源码自己编译的,Linux下面是make编译,你windows下就用cmake编译一下然后再导入你的vs里面呗。

报错信息发出来一下,线索可能在错误信息里面。