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

时间:2011-02-27 17:23:11

标签: c++

我编写了一些类来实现一个树ADT,它存储两个边集和一个节点。它存储的是SSet类,它们是使用set库的接口。

班级和SSet.H的大纲由工作人员提供给我们,我写了这些函数。

编号(103)(函数GenGraphTemp::RemoveEdge)编译器(g ++)告诉:

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

也适用于RemoveEdge之后的功能:

第106行

expected ';' before "const"

第120行

expected ';' before "SSet"expected ';' before "const"

第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;
};

我无法理解问题出在哪里和什么地方。

编辑:

我删除了Edge类的函数和运算符的实现,以减少行。 我没有删除GenGraphTemp类的实现,因为我不知道问题是否与其中一个或其他地方有关。

我还尝试在备注中使用每个“好”函数编译代码,但它没有帮助。

1 个答案:

答案 0 :(得分:3)

// 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) {

// 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 {

等......