首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编译错误:命名空间‘std’中的‘函数’没有命名模板类型“

编译错误:命名空间‘std’中的‘函数’没有命名模板类型“
EN

Stack Overflow用户
提问于 2016-09-19 10:42:15
回答 1查看 5.4K关注 0票数 3

我正在尝试使用http://libtins.github.io/download/库来嗅探我的网络流量。因此,我下载了tar.gz库,并成功地完成了手册中提到的所有库编译步骤。

现在,我正在尝试编译我的第一个示例程序:

代码语言:javascript
复制
  1 #include <iostream>
  2 #include <tins/tins.h>
  3 
  4 using namespace Tins;
  5 
  6 bool callback(const PDU &pdu) {
  7     const IP &ip = pdu.rfind_pdu<IP>(); // Find the IP layer
  8     const TCP &tcp = pdu.rfind_pdu<TCP>(); // Find the TCP layer
  9     std::cout << ip.src_addr() << ':' << tcp.sport() << " -> "
 10               << ip.dst_addr() << ':' << tcp.dport() << std::endl;
 11     return true;
 12 }
 13 
 14 int main() {
 15     Sniffer("eth0").sniff_loop(callback);
 16 }  

当我想编译它时,我会遇到以下错误:

代码语言:javascript
复制
me@me-MS-7693:~/Desktop/Workspace/cpp_libtins$ g++ main.cpp -ltins
In file included from /usr/local/include/tins/tins.h:60:0,
                 from main.cpp:2:
/usr/local/include/tins/crypto.h:297:18: error: ‘function’ in namespace ‘std’ does not name a template type
     typedef std::function<void(const std::string&,
                  ^
/usr/local/include/tins/crypto.h:308:18: error: ‘function’ in namespace ‘std’ does not name a template type
     typedef std::function<void(const std::string&,
                  ^
/usr/local/include/tins/crypto.h:401:44: error: ‘handshake_captured_callback_type’ does not name a type
     void handshake_captured_callback(const handshake_captured_callback_type& callback);
                                            ^
/usr/local/include/tins/crypto.h:412:34: error: ‘ap_found_callback_type’ does not name a type
     void ap_found_callback(const ap_found_callback_type& callback);
                                  ^
/usr/local/include/tins/crypto.h:445:9: error: ‘handshake_captured_callback_type’ does not name a type
         handshake_captured_callback_type handshake_captured_callback_;
         ^
/usr/local/include/tins/crypto.h:446:9: error: ‘ap_found_callback_type’ does not name a type
         ap_found_callback_type ap_found_callback_;
         ^
me@me-MS-7693:~/Desktop/Workspace/cpp_libtins$ 

怎么啦?

我的编译器版本:

代码语言:javascript
复制
me@me-MS-7693:~/Desktop/Workspace/cpp_libtins$ g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

me@me-MS-7693:~/Desktop/Workspace/cpp_libtins$ 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-19 10:47:05

由于您的GCC年龄大于6.0,您需要通过-std=c++11交换机,otherwise it is in C++03 mode。C++03没有std::function

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39571199

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档