Я не смог найти ответ, я надеюсь, что вы, ребята, можете мне помочь.
Я создал два класса 1.GraphMatrix 2.GraphList оба они находятся в публичном c наследовании с классом Graph (виртуальный класс) , Затем я хотел перегрузить "=" для классов 1 и 2. После реализации второго перезагружено первое «=». Я думаю, что это может каким-то образом скрывать методы. Может кто-нибудь объяснить мне, почему это происходит и как это решить.
#include <iostream>
#include "GrafList.cpp"
#include "Graf.cpp"
int main() {
GrafMatrix<int,30> Gm;
Gm.fill(0.5);
GrafList<int,30> G;
Gm.fill(1);
Gm = G;
G = Gm;
return 0;
}
Заголовок GraphMatrix
#include "Graf.cpp"
#include "GrafList.h"
template <class Type, int MAXIMUM>
class GrafMatrix : public Graf<Type,MAXIMUM> {
private:
int adjacencyMatrix [MAXIMUM][MAXIMUM]{};
public:
GrafMatrix();
~GrafMatrix();
void addVertex(const Type& value);
void addEdge(int source, int target, int value = 1);
void removeEdge(int source, int target);
void fill(double density,int maxWeight = MAXIMUM);
void print();
int GetEdge(int source, int target)const;
Type& operator [] (int vertex);
Type operator [] (int vertex)const;
GrafMatrix &operator =(GrafList<Type,MAXIMUM> &G);
bool isEdge(int source, int target);
std::set<int> neighbours(int vertex)const;
};
Заголовок GraphList
#include "GrafMatrix.h"
#include "Graf.cpp"
template <typename Type,int MAXIMUM>
class GrafList:public Graf<Type,MAXIMUM> {
private:
std::vector<Edge> Edges;
public:
GrafList();
~GrafList();
void addVertex(const Type& value);
void addEdge(int source, int target, int value = 1);
void removeEdge(int source, int target);
void fill(double density,int maxWeight = MAXIMUM);
void print();
Type& operator [] (int vertex);
Type operator [] (int vertex)const;
GrafList&operator =(GrafMatrix<Type,MAXIMUM> &G);
bool isEdge(int source, int target);
std::set<int> neighbours(int vertex)const;
};