debug websocket ++ broadcast_server.cpp('owner_less'不是'std'的成员)

2 c++ compiler-errors std member websocket++

Zaphoyd broadcast_server.cpp看起来像是websocket服务器的完美骨干,它可以快速接受并发送消息和连接与线程进行实际操作,从而不会中断通信. https://github.com/zaphoyd/websocketpp/blob/experimental/examples/broadcast_server/broadcast_server.cpp

他的简单print_server.cpp例子很容易编译; 但是,我得到了一些编译错误broadcast_server.cpp.

root@server:~# g++ -O3 broadcast_server.cpp -I ~/websocketpp-experimental/ -lboost_system
broadcast_server.cpp:126:37: error: 'owner_less' is not a member of 'std'
broadcast_server.cpp:126:37: error: 'owner_less' is not a member of 'std'
broadcast_server.cpp:126:70: error: 'con_list' was not declared in this scope
broadcast_server.cpp:126:70: error: template argument 2 is invalid
broadcast_server.cpp:126:18: warning: 'typedef' was ignored in this declaration [enabled by default]
broadcast_server.cpp:129:5: error: 'con_list' does not name a type
broadcast_server.cpp: In member function 'void broadcast_server::process_messages()':
broadcast_server.cpp:109:17: error: 'm_connections' was not declared in this scope
broadcast_server.cpp:112:17: error: 'm_connections' was not declared in this scope
broadcast_server.cpp:116:17: error: 'con_list' has not been declared
broadcast_server.cpp:116:36: error: expected ';' before 'it'
broadcast_server.cpp:117:22: error: 'it' was not declared in this scope
broadcast_server.cpp:117:27: error: 'm_connections' was not declared in this scope
Run Code Online (Sandbox Code Playgroud)

我是c ++的新手,这些可能是简单的问题,但我无法通过它们找到方法.

'owner_less' is not a member of 'std'http://en.cppreference.com/w/cpp/memory/owner_less

我猜测,template argument 2 error当上述问题解决后,意志就会消失.

'con_list' was not declared in this scope什么时候在那里private:?跟'm_connections'?一样?

我猜这'con_list' has not been declared会在上述错误发生时消失.

我不知道'it'它在谈论它或为什么它应该;在它面前.

版本

Ubuntu 12.10

gcc --version gcc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2

提升1.53.0

额外#include

#include <cstdlib>
#include <iostream>
#include <memory>
#include <set>
Run Code Online (Sandbox Code Playgroud)

依然没有

-std=c++11

In file included from /usr/include/c++/4.7/map:60:0,
                 from /usr/local/include/boost/date_time/gregorian/greg_month.hpp:18,
                 from /usr/local/include/boost/date_time/gregorian/greg_ymd.hpp:16,
                 from /usr/local/include/boost/date_time/gregorian/greg_calendar.hpp:16,
                 from /usr/local/include/boost/date_time/gregorian/gregorian_types.hpp:19,
                 from /usr/local/include/boost/date_time/posix_time/posix_time_config.hpp:18,
                 from /usr/local/include/boost/date_time/posix_time/posix_time_system.hpp:13,
                 from /usr/local/include/boost/date_time/posix_time/ptime.hpp:12,
                 from /usr/local/include/boost/date_time/posix_time/posix_time_types.hpp:12,
                 from /usr/local/include/boost/thread/thread_time.hpp:11,
                 from /usr/local/include/boost/thread/lock_types.hpp:18,
                 from /usr/local/include/boost/thread/pthread/thread_data.hpp:12,
                 from /usr/local/include/boost/thread/thread.hpp:17,
                 from /usr/local/include/boost/thread.hpp:13,
                 from /root/websocketpp-experimental/websocketpp/common/thread.hpp:41,
                 from /root/websocketpp-experimental/websocketpp/concurrency/basic.hpp:31,
                 from /root/websocketpp-experimental/websocketpp/config/core.hpp:35,
                 from /root/websocketpp-experimental/websocketpp/config/asio_no_tls.hpp:31,
                 from broadcast_server.cpp:1:
/usr/include/c++/4.7/bits/stl_tree.h: In instantiation of 'class std::_Rb_tree<boost::weak_ptr<void>, boost::weak_ptr<void>, std::_Identity<boost::weak_ptr<void> >, std::owner_less<boost::weak_ptr<void> >, std::allocator<boost::weak_ptr<void> > >':
/usr/include/c++/4.7/bits/stl_set.h:116:17:   required from 'class std::set<boost::weak_ptr<void>, std::owner_less<boost::weak_ptr<void> > >'
broadcast_server.cpp:132:14:   required from here
/usr/include/c++/4.7/bits/stl_tree.h:471:31: error: invalid use of incomplete type 'struct std::owner_less<boost::weak_ptr<void> >'
In file included from /usr/include/c++/4.7/bits/shared_ptr.h:52:0,
                 from /usr/include/c++/4.7/memory:87,
                 from /usr/local/include/boost/config/no_tr1/memory.hpp:21,
                 from /usr/local/include/boost/smart_ptr/shared_ptr.hpp:27,
                 from /usr/local/include/boost/shared_ptr.hpp:17,
                 from /usr/local/include/boost/date_time/time_clock.hpp:17,
                 from /usr/local/include/boost/thread/thread_time.hpp:9,
                 from /usr/local/include/boost/thread/lock_types.hpp:18,
                 from /usr/local/include/boost/thread/pthread/thread_data.hpp:12,
                 from /usr/local/include/boost/thread/thread.hpp:17,
                 from /usr/local/include/boost/thread.hpp:13,
                 from /root/websocketpp-experimental/websocketpp/common/thread.hpp:41,
                 from /root/websocketpp-experimental/websocketpp/concurrency/basic.hpp:31,
                 from /root/websocketpp-experimental/websocketpp/config/core.hpp:35,
                 from /root/websocketpp-experimental/websocketpp/config/asio_no_tls.hpp:31,
                 from broadcast_server.cpp:1:
/usr/include/c++/4.7/bits/shared_ptr_base.h:270:12: error: declaration of 'struct std::owner_less<boost::weak_ptr<void> >'
Run Code Online (Sandbox Code Playgroud)

我是如何安装的(依赖项,实际程序等)

https://github.com/zaphoyd/websocketpp/wiki/Setup-0.3X-on-Ubuntu-12.10

替代品欢迎

如果有人有替代品std::owner_less,请发布.

zap*_*oyd 5

std :: owner_less是一个C++ 11 STL功能,允许您将std :: weak_ptr放在关联容器中,如set和map.最终,connection_hdl是一个weak_ptr,这就是它需要自定义比较功能的原因.

WebSocket ++ 0.3.x可以通过预处理器定义配置为使用C++ 03 + Boost或C++ 11.默认情况下,它使用C++ 03 + Boost.Boost weak_ptr的工作方式略有不同,不需要自定义比较功能.如果使用列表,队列或向量,则也不必要,因为这些容器不使用connection_hdl作为键.

0.3.x手册中的大多数示例与库捆绑使用C++ 11,因为它更加简洁明了.要按原样编译和链接这些示例,您需要一个C++ 11编译器并使用适当的C++ 11编译器标志和WebSocket ++定义.Scons是我用来自动构建和运行所有示例和单元测试的构建系统.没有必要构建和运行单个示例程序.任何其他构建系统都应该可以正常工作,就像在命令行上特别提供编译器参数一样.

我在手册中设置了一个页面,其中描述了启用/禁用C++ 11功能的各种选项.http://www.zaphoyd.com/websocketpp/manual/reference/cpp11-support.本手册页面列出了我最常用于测试的操作系统和编译器的推荐编译器标志.

对于Linux上的g ++ 4.7,我建议:" - std = c ++ 0x -D_WEBSOCKETPP_CPP11_STL_ -D_WEBSOCKETPP_NO_CPP11_REGEX_ -lboost_regex -lboost_system".这样可以启用除库之外的所有C++ 11功能(这是破坏/错误),而是引入Boost版本.