请求从“std::vector<AdjacencyData> (*)()”到非标量类型“std::vector<AdjacencyData>”的转换

conversion from ‘std::vector<AdjacencyData> (*)()’ to non-scalar type ‘std::vector<AdjacencyData>’ requested

我定义了一个 Lsdb class,其函数和参数如下。

47   AdjacencyData
48   getAdjacentNode(const std::string routerName, const std::string adjacentNodeName);
49 
50 private:
51   std::vector<AdjacencyData> m_AdjacencyList;
52   std::map<std::string, std::vector<AdjacencyData>()> m_Lsdb;

在该方法的实现中,我有以下代码。

 43 Lsdb::getAdjacentNode(const std::string routerName, const std::string nodeName)
 44 {
 45 
 46   AdjacencyData nodeData;
 47 
 48   // Get the adjacency list for given router.
 49   std::map<std::string, std::vector<AdjacencyData>()>::iterator itr = m_Lsdb.find(routerName);
 50   if (itr != m_Lsdb.end())
 51   {
 52     // Get the specific node data from list.
 53     std::vector<AdjacencyData> nodeList = itr->second;
 54 
 55     std::vector<AdjacencyData>::iterator listItr = nodeList.begin();
 56     for(; listItr != nodeList.end(); listItr++)
 57     {
 58       nodeData = *listItr;
 59       if (nodeData.getRouterName().compare(nodeName))
 60       {
 61         return nodeData;
 62       }
 63     }
 64   }
 65 
 66   return nodeData;
 67 }

编译时出现以下错误。有人可以帮助理解这段代码有什么问题吗?

In file included from /usr/include/c++/4.6/bits/stl_algobase.h:65:0,
                 from /usr/include/c++/4.6/bits/char_traits.h:41,
                 from /usr/include/c++/4.6/ios:41,
                 from /usr/include/c++/4.6/ostream:40,
                 from /usr/include/c++/4.6/iostream:40,
                 from ./ns3/assert.h:48,
                 from ../src/lsdb.cc:22:
/usr/include/c++/4.6/bits/stl_pair.h: In instantiation of ‘std::pair<const std::string, std::vector<AdjacencyData>()>’:
../src/lsdb.cc:50:25:   instantiated from here
/usr/include/c++/4.6/bits/stl_pair.h:93:11: error: field ‘std::pair<const std::string, std::vector<AdjacencyData>()>::second’ invalidly declared function type
../src/lsdb.cc: In member function ‘AdjacencyData Lsdb::getAdjacentNode(std::string, std::string)’:
../src/lsdb.cc:53:48: error: conversion from ‘std::vector<AdjacencyData> (*)()’ to non-scalar type ‘std::vector<AdjacencyData>’ requested

你的错误在这一行:

std::map<std::string, std::vector<AdjacencyData>()>::iterator itr = m_Lsdb.find(routerName);

你把 std::vector<AdjacencyData>() 作为函数 std::map 的第二种类型,你应该使用 std::vector<AdjacencyData>.