我有以下代码,它具有循环依赖性以及每个类使用不同的名称空间。我收到以下编译错误。我不确定解决此错误的正确解决方案是什么。试了几件事但不成功。有人可以指出正确的代码吗?
除了循环依赖之外,我更不清楚不同命名空间的含义(如果有的话),以及它如何以某种方式影响依赖关系。
我已粘贴原始程序文件的摘录。
// ndn-nlsr-app.hpp
19 #include "model/nlsr/name-prefix-table.hpp"
21
22 namespace ns3 {
23 namespace ndn {
24
25 class NlsrApp: public App {
26
27 public:
65 nlsr::NamePrefixTable&
66 getNamePrefixTable()
67 {
68 return m_namePrefixTable;
69 }
70
103 nlsr::NamePrefixTable m_namePrefixTable;
108 };
109
110 }//namespace ndn
111 }//namespace ns3
// name-prefix-table.hpp
9 #include "apps/ndn-nlsr-app.hpp"
10 namespace ns3 {
11 namespace nlsr {
12
13 class NamePrefixTable
14 {
15 public:
16 NamePrefixTable(ndn::NlsrApp& nlsr)
17 : m_nlsr(nlsr)
18 {
19 }
40 private:
41 ndn::NlsrApp& m_nlsr;
42 };
44
45 }//namespace nlsr
46 }//namespace ns3
In file included from ../src/ndnSIM/apps/ndn-nlsr-app.hpp:19:0,
from ../src/ndnSIM/apps/ndn-nlsr-app.cpp:1:
../src/ndnSIM/model/nlsr/name-prefix-table.hpp:17:31: error: expected ‘)’ before ‘&’ token
../src/ndnSIM/model/nlsr/name-prefix-table.hpp:42:3: error: ‘NlsrApp’ in namespace ‘ns3::ndn’ does not name a type
In file included from ../src/ndnSIM/model/nlsr/name-prefix-table.hpp:9:0,
from ../src/ndnSIM/model/nlsr/name-prefix-table.cpp:5:
../src/ndnSIM/apps/ndn-nlsr-app.hpp:65:3: error: ‘NamePrefixTable’ in namespace ‘ns3::nlsr’ does not name a type
../src/ndnSIM/apps/ndn-nlsr-app.hpp:103:3: error: ‘NamePrefixTable’ in namespace ‘ns3::nlsr’ does not name a type