从'std :: vector <adjacencydata>(*)()'转换为非标量类型'std :: vector <adjacencydata>'requested </adjacencydata> </adjacencydata>

时间:2015-02-16 00:25:39

标签: c++ dictionary vector stl iterator

我已经使用函数和参数定义了一个Lsdb类,如下所示。

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

1 个答案:

答案 0 :(得分:1)

你错误就在这一行:

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

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