简体   繁体   中英

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. it stores them is SSet classes, which are an interface to use the set library.

The outlines of the classes as well as SSet.H were given to us by the staff and I wrote the functions.

line number 103 (function GenGraphTemp::RemoveEdge ) the compiler (g++) tells:

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:

expected ';' before "const" expected ';' before "const" for line 106

expected ';' before "SSet" expected ';' before "SSet" and expected ';' before "const" expected ';' before "const" for line 120

expected ';' before "friend" expected ';' before "friend" for line 134

#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. 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.

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 ....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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