データ構造体クラスのグラフクラスで作業していて、ライン上のオブジェクト:使用するときに " - を使用すると"クラスへのポインタ型でなければならない "と指定するオブジェクト
myGraph.nodes[a]->edges.back.n1 = myGraph.nodes[a];
myGraph.nodes[a]->edges.back->n2 = myGraph.nodes[b];
myGraph.nodes[a]->edges.back.cost = c;
私はそれはそれはそれはポインタとクラスのタイプ(C2227)でなければならないと言われますポインタであるかのようにオブジェクトを操作しようとすると、私はそれを操作しようとした場合(C2228)
私は、この問題で私の仲間にやり遂げる方法を知っているすべてのことを試みました(私の教授には到達できません)。私は、メンバーを参照する第3のタイプまたは方法について認識していません。
私はlab11のコードがうまく動作することを知っているmain.cppファイルにすべての問題を含める必要があります。
これらはすべてポインタであるため、 - >演算子で参照する必要がありますが、単純にそうではありません。私はそれが眉をひそめているどのくらい知っているが、私は、私は他のオプションのうち、単純ですので
main.cppに
#include <iostream>
#include <fstream>
#include "lab11.cpp";
using namespace std;
int main() {
}
Graph writeGraph(string filename) {
ifstream myfile;
myfile.open(filename);
int numberofnodes;
myfile >> numberofnodes;
Graph myGraph;
for (int i = 0; i < numberofnodes; i++) {
myGraph.nodes.push_back(new Node(i));
}
int a = 0, b = 0, c = 0;
while (myfile >> a) {
if (a == -1) {
break;
}
myfile >> b >> c;
Edge *newEdge();
Node * temp = myGraph.nodes[a];
myGraph.nodes[a]->edges.push_back(new Edge());
myGraph.nodes[a]->edges.back.n1 = myGraph.nodes[a];
myGraph.nodes[a]->edges.back->n2 = myGraph.nodes[b];
myGraph.nodes[a]->edges.back.cost = c;
}
}
lab11.cpp
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
class Node;
class Edge {
public:
Edge() { n1 = 0; n2 = 0; inspanningtree = false; }
Node * n1;
Node * n2;
int cost;
bool inspanningtree;
};
class Node {
public:
Node(int nodeNumber)
{
this->nodeNumber = nodeNumber;
lastnum = -1;
}
int nodeNumber;
vector<Edge *> edges;
int lastnum;
};
class Graph {
public:
vector<Node *> nodes;
vector<Edge *> edges;
};
/*
void shellsortEdge(vector<Edge *> & a)
{
for(int gap = a.size()/2; gap > 0; gap /= 2)
for(int i = gap; i < a.size(); ++i)
{
Edge * tmp = std::move(a[ i ]);
int j = i;
for(; j >= gap && *tmp < *(a[ j - gap ]); j -= gap)
a[ j ] = std::move(a[ j - gap ]);
a[ j ] = std::move(tmp);
}
}*/
int glastnum = 0;
bool find(Node * current, Node * tofind, Node * from)
{
for (unsigned int i = 0; i < current->edges.size(); i++) {
if (current->edges[i]->inspanningtree) {
if (current->edges[i]->n1 != from && current != current->edges[i]->n1)//prob
{
if (current->edges[i]->n1->lastnum == glastnum) {
return true;
}
current->edges[i]->n1->lastnum = glastnum;
bool b = find(current->edges[i]->n1, tofind, current);
if (b == true)
return true;
}
if (current->edges[i]->n2 != from && current != current->edges[i]->n2)//prob
{
if (current->edges[i]->n2->lastnum == glastnum) {
return true;
}
current->edges[i]->n2->lastnum = glastnum;
bool b = find(current->edges[i]->n2, tofind, current);
if (b == true)
return true;
}
}
}
return false;
}
bool doesAddingThisMakeACycle(Graph & g, Edge * toBeAdded)
{
toBeAdded->inspanningtree = true;
glastnum++;
Node * n1 = toBeAdded->n1;
Node * n2 = toBeAdded->n2;
bool b = find(n1, n1, n1);
if (b) {
toBeAdded->inspanningtree = false;
return true;
}
glastnum++;
b = find(n2, n2, n2);
if (b) {
toBeAdded->inspanningtree = false;
return true;
}
toBeAdded->inspanningtree = false;
return false;
}
は私が宿題の助けのためにここに来ることを憎みますこれがうまくいけば削除します
'エッジを削除は*ニューエッジ();' ' –
edges.back.n1'は' edges.back(なければならない) - > n1'、同様cost' 'のために直後に「n2」と表示されます。 –
@ M.M 'back'はメンバ変数ではなく、' std :: vector'の中の関数です。 'edges.back() - > n1'にする必要があります。 –