简体   繁体   English

C ++中预期的嵌套名称说明符错误

[英]expected nested-name-specifier error in C++

I've written classes to implement a tree ADT that stores two sets one of edges and one of nodes. 我编写了一些类来实现树ADT,该树ADT存储边缘和节点之一的两个集合。 it stores them is SSet classes, which are an interface to use the set library. 它存储的是SSet类,它们是使用set库的接口。

The outlines of the classes as well as SSet.H were given to us by the staff and I wrote the functions. 工作人员将类的概述以及SSet.H交给了我们,我编写了函数。

line number 103 (function GenGraphTemp::RemoveEdge ) the compiler (g++) tells: 行号103(函数GenGraphTemp::RemoveEdge ),编译器(g ++)告诉:

expected nested-name-specifier before NodeEdge
expected ',' or '...' before '&' token
ISO C++ forbids declaration of 'NodeEdge' with no type

also for the functions following RemoveEdge it says: 还针对RemoveEdge之后的功能说:

expected ';' before "const" expected ';' before "const" for line 106 expected ';' before "const"第106行的expected ';' before "const"

expected ';' before "SSet" expected ';' before "SSet" and expected ';' before "const" expected ';' before "SSet"expected ';' before "const" expected ';' before "const" for line 120 expected ';' before "const"第120行的expected ';' before "const"

expected ';' before "friend" expected ';' before "friend" for line 134 expected ';' before "friend"第134行的expected ';' before "friend"

#include "sset.H"

using namespace std;

#define EQ(a1,a2) (!(a1 < a2) && !(a2 < a1))
#define MAX(a1,a2) ((a2<a1)?a1:a2)
#define MIN(a1,a2) ((a1<a2)?a1:a2)

template <class Node>
class Edge {
public:
    ...

protected:
    Node _start;
    Node _end;
};


template <class Node>
class GenGraphTemp {
public:

    // Adds a new node to the nodes set
    bool AddNode (const Node& n1){return _nodes.Add(n1);}

    // Removes a node from the nodes set and all edges connected to it
    bool RemoveNode (const Node& n1) {
        int edges_size = _edges.Size();
        int i;
        Edge const *epointer;
        //remove edges connected to n1
        for (i=0;i<edges_size;i++){
            (((i==0)? *epointer=_edges.GetFirst(): *epointer=_edges.GetNext()));
            if (EQ(epointer->GetStart(),n1)||EQ(epointer->GetEnd(),n1)){
                (_edges.Remove(*epointer)==false) && (return false);
            }
        }
        // remove node
        return _nodes.Remove(n1);
    }

    // Add a new edge to the edges set
    bool AddEdge (const Node& n1, const Node& n2) {

        (EQ(n1,n2)) && (return false);

        if ((_nodes.IsIn(n1)) && (_nodes.IsIn(n2))){
            typename NodeEdge edge(n1,n2);
            return _edges.Add(edge);
        }
        return false;
    }

    // Removes an edge from edges set
    bool RemoveEdge (const typename NodeEdge& e1) {return _edges.Remove(e1);}

    // Check if two nodes are connected
    bool RConnected const (const Node& n1, const Node& n2) {
        Edge const *epointer;
        int edges_size = _edges.Size();
        int i;
        for (i=0; i<edges_size; i++){
            ((i==0)? *epointer=_edges.GetFirst(): *epointer=_edges.GetNext());
            if (EQ(epointer->GetStart(),MIN(n1,n2)) && EQ(epointer->GetEnd(),MAX(n1,n2))){
                return true;
            }
        }
    }

    // Return a set of all the nodes that are connected to the input node through an edge
    // if the node does not have ant neighbours, the function will return an empty set
    SSet<Node>* Neighbours const (const Node& n1) {
        Edge const *epointer;
        int i, edge_size;
        SSet<Node>* neighbours = new SSet<Node>;
        edge_size=_edges.Size();
        for (i=0; i<edges_size; i++){
            ((i==0)? *epointer=_edges.GetFirst(): *epointer=_edges.GetNext());
            if (EQ(epointer->GetStart(),n1)||EQ(epointer->GetEnd(),n1)){
                (neighbours->IsIn(*epointer)) || (neighbours->Add(*epointer);
            }
        }
        return neighbours;
    }

    friend ostream& operator<<(ostream& os, GenGraphTemp<Node>& gr)
    {
        os << "Nodes:\n" << gr._nodes << "Edges:\n" << gr._edges;
        return os;
    }


protected:
    typedef Edge<Node> NodeEdge;
    SSet<Node> _nodes;
    SSet<NodeEdge> _edges;
};

I can't understand where and what is the problem. 我不明白问题出在什么地方和什么地方。

Edit: 编辑:

I've removed the implementation of the functions and operators for the Edge class to cut down on lines. 我删除了Edge类的函数和运算符的实现,以减少行数。 I didn't remove the implementation of the GenGraphTemp class because I don't know if the problem is with one of them or elsewhere. 我没有删除GenGraphTemp类的实现,因为我不知道问题出在其中之一还是其​​他地方。

I've also tried to compile the code with each "good" function in remarks and it didn't help. 我还尝试在备注中使用每个“良好”函数来编译代码,但这没有帮助。

// Removes an edge from edges set
bool RemoveEdge (const typename NodeEdge& e1) {return _edges.Remove(e1);}

// Check if two nodes are connected
bool RConnected const (const Node& n1, const Node& n2) {

make 使

// Removes an edge from edges set
bool RemoveEdge (const NodeEdge& e1) {return _edges.Remove(e1);}

// Check if two nodes are connected
bool RConnected (const Node& n1, const Node& n2) const {

etc .... 等等...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM