我为项目运行‘Topology’ does not name a type
DeSiNe [点击进入github页面],我收到错误$ make build
mkdir -m 755 -p obj/Algorithm
g++ -Wall -DNO_TIMER -DNO_TRACES -O3 -funroll-loops -finline-functions -fexpensive-optimizations -Isrc -o obj/Algorithm/Algorithm.o -c src/Algorithm/Algorithm.cpp
In file included from src/Network/TopologyFactory.h:21:0,
from src/Network/Topology.h:25,
from src/Network/Flow.h:20,
from src/Algorithm/Algorithm.h:20,
from src/Algorithm/Algorithm.cpp:14:
src/RandomVariables/RandomNumberGenerator.h: In member function ‘double RandomNumberGenerator::generate()’:
src/RandomVariables/RandomNumberGenerator.h:158:43: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
return (double) 2.0 - (*(float*) &itemp);
^
In file included from src/Network/Topology.h:25:0,
from src/Network/Flow.h:20,
from src/Algorithm/Algorithm.h:20,
from src/Algorithm/Algorithm.cpp:14:
src/Network/TopologyFactory.h: At global scope:
src/Network/TopologyFactory.h:76:5: error: ‘Topology’ does not name a type
Topology* create(const TString &description);
^
src/Network/TopologyFactory.h:84:48: error: ‘Topology’ has not been declared
void build(const NodePairDeque &nodepairs, Topology* topology);
^
src/Network/TopologyFactory.h:92:5: error: ‘Topology’ does not name a type
Topology* createTopologyAdjacency(const TString &description);
^
src/Network/TopologyFactory.h:103:5: error: ‘Topology’ does not name a type
Topology* createTopologyBarabasi(const TString &description);
^
src/Network/TopologyFactory.h:112:5: error: ‘Topology’ does not name a type
Topology* createTopologyErdos(const TString &description);
^
src/Network/TopologyFactory.h:120:5: error: ‘Topology’ does not name a type
Topology* createTopologyFile(const TString &description);
^
src/Network/TopologyFactory.h:129:5: error: ‘Topology’ does not name a type
Topology* createTopologyFull(const TString &description);
^
src/Network/TopologyFactory.h:138:5: error: ‘Topology’ does not name a type
Topology* createTopologyGrid2D(const TString &description);
^
src/Network/TopologyFactory.h:147:5: error: ‘Topology’ does not name a type
Topology* createTopologyRandom(const TString &description);
^
make: *** [Algorithm/Algorithm] Error 1
Topology.h
但包含的class Topology : public AbstractNetworkElement
{
// Friend(s)
确实包含
In file included from src/Algorithm/SamcraBAlgorithm.h:22:0,
from src/Algorithm/SamcraBAlgorithm.cpp:17:
src/Utils/TString.h:25:7: error: using typedef-name ‘Types::TString’ after ‘class’
class TString
^
In file included from src/LinkStateUpdate/LinkStateUpdateVisitor.h:23:0,
from src/Network/Link.h:19,
from src/Network/Topology.h:23,
from src/Network/Flow.h:20,
from src/Algorithm/Algorithm.h:22,
from src/Algorithm/SamcraBAlgorithm.cpp:16:
src/Utils/Types.h:65:24: note: ‘Types::TString’ has a previous declaration here
typedef deque<string> TString;
^
make: *** [Algorithm/SamcraBAlgorithm] Error 1
如何解决?
编辑: 为类拓扑添加前向声明会产生进一步的错误:
<data>
<points>
<score>80</score>
<score>90</score>
<score>10</score>
<score>13</score>
</points>
<favor>50</favor>
<ranked>
<rank>50</rank>
<rank>10</rank>
</ranked>
</data>
答案 0 :(得分:2)
基本上该项目有四个主要的编译问题:
第一个修复涉及从拓扑标题中删除TopologyFactory,从而打破循环包含依赖关系。然后包含需要的TopologyFactory标题。
第二个很容易修复:只需删除TString头包含,因此它默认使用Utils / Types.h中的定义。
第三个修复是微不足道的:只需在需要的地方添加cstdio / cstdlib。
最后一个修复涉及将静态初始化移动到定义文件(也许作者使用的旧编译器具有允许此类初始化的扩展名。)
我对此gist做了补丁,因此您可以看到更改。该项目在Ubuntu 15.10上使用g ++ 5.2.1进行编译。
答案 1 :(得分:1)
代码中有交叉引用。
Topology.h包含TopologyFactory.h,反之亦然TopologyFactory.h包含Topology.h
最简单的修复方法是将类Topology的前向声明添加到TopologyFactory.h中:
#ifndef TOPOLOGYFACTORY_H
#define TOPOLOGYFACTORY_H
...
class Topology;
class TopologyFactory
{
更正确的方法是尝试解决这些依赖关系,即不要在Topology.h中包含TopologyNetwork.h,然后在使用TopologyNetwork和Topology的所有cpp文件中添加两个include指令:
/*
source file DesineModel.cpp for class: DesineModel
...
*/
...
#include "Network/Topology.h"
#include "Network/TopologyFactory.h"
...