#include<iostream>
#include<cstdio>
#include<list>
#include<vector>
usingnamespace std;
#define MAX 100001
class Graph
{
public:
class edge
{
public:
int u,v,weight;
};
vector<edge> elist;
int vertices;
};
int main()
{
int n,k,x,y,w;
Graph graph;
scanf("%d%d",&n,&k);
for(int i=0;i<n-1;i++)
{
scanf("%d%d%d",&x,&y,&w);
graph.elist.push_back(graph.edge{x,y,w});
}
}
In the last line "graph.edge{x,y,w}" it says typename is not allowed?
I have used nested class edge and pushing vertices and their weight in elist vector which is of type edge.
Please help!!
In the last line "graph.edge{x,y,w}" it says typename is not allowed?
It is referring to the word "edge" after the member access operator . (dot)
Member access operators only allow data members, member functions, and enumerators on the right. Type names are not allowed.
(the standardese for this is "If E2 is a nested type, the expression E1.E2 is ill-formed" in ยง 5.2.5[expr.ref]/4)
Now if you replace that with Graph::edge, which names a type, it will compile