对于个人项目,我想创建一个通用图。 我创建了2个类:OrientedNode类和ClassicArrow类。
这是类文件: -节点类文件
#pragma once
#include <iostream>
#include <vector>
//BEGIN OF THE CLASS CLASSICNODE:MOTHER CLASS OF EVERY TYPE OF NODE
class ClassicNode{
protected:
unsigned int nodeId;
public:
//Constructor
ClassicNode();
ClassicNode(unsigned int NodeId);
//Getters
unsigned int getId()const;
//Operator
friend std::ostream& operator<<(std::ostream& outputStream, const ClassicNode& N){
return outputStream << N.getId()<<std::endl;
}
bool operator ==(const ClassicNode& N);
};
//BEGIN OF THE CLASS ORIENTEDNODE:
// -IT INHERITS THE CLASS NODE
// -IT REPRESENTS THE NODE IN A ORIENTED GRAPHE
template <typename ARROW> class OrientedNode: public ClassicNode{
protected:
std::vector<ARROW> listArrowsIn;
std::vector<ARROW> listArrowsOut;
public:
//Constructor
OrientedNode();
OrientedNode(unsigned int NodeId);
//Getter
std::vector<ARROW> getListArrowIn()const;
std::vector<ARROW> getListArrowOut()const;
//Manipulation
void addArrowIn(const ARROW& A);
void addArrowOut(const ARROW& A);
};
-Arc类文件:
#pragma once
#include <iostream>
template <typename NODE> class ClassicArrow
{
protected:
unsigned int origineNodeId;//Id of the node where the arrow begin
unsigned int destinationNodeId;//Id of the node where the arrow end
float distance;
NODE* targetNode;//Pointer to the node where the arrow end
public:
//Constructor
ClassicArrow();
ClassicArrow(const ClassicArrow<NODE>& A);
ClassicArrow(unsigned int OrigineNodeId,unsigned int DestinationNodeId,float Distance,NODE* TargetNode);
//Getters
unsigned int getOrigineNodeId()const;
unsigned int getDestinationNodeId()const;
float getDistance()const;
NODE* getTargetNode()const;
//Operator
void operator=(const ClassicArrow<NODE>& A);
NODE& operator*(void);
friend std::ostream& operator<<(std::ostream& outputStream, const ClassicArrow<NODE>& A){
return outputStream <<"IdBegin="<<A.getOrigineNodeId()<< "IdEnd="<<A.getDestinationNodeId()<<"distance="<<A.getDistance()<<std::endl;
}
};
OrientedNode类和ClassicArrow类嵌套在一起。 我想用模板类参数ClassicArrow(主文件中的文件)声明一个OrientedNode变量。我该怎么办?
#include <iostream>
#include <vector>
#include "ClassicArrow.h"
#include "ClassicNode.h"
int main() {
//Code for a Oriented Node variable declaration
}