The below code snippet is generating the error: expected identifier before 'nullptr' as well as error: expected ',' or '...' before 'nullptr' in line edge minIncoming(nullptr, NOPATH);
Any idea what is wrong? All I want to do is use the constructor to initialize minIncoming. I tried searching but couldn’t find a answer. I apologize in advance if question is too basic.
#include <vector>
#include <unordered_map>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <queue>
#define MAXN 8
#define NOPATH 1000000
#define DEBUG
using namespace std;
struct vertex;
struct edge
{
vertex* node;
int weight;
edge(vertex* n, int w) : node(n), weight(w) {}
};
struct vertex
{
vector< edge > outgoing;
edge minIncoming(nullptr, NOPATH);
bool visited;
#ifdef DEBUG
int id;
#endif // DEBUG
};
>Solution :
Due to most C++’s most vexing parse, the statement:
edge minIncoming(nullptr, NOPATH);
is treated as if you’re declaring a function named minIncoming with return type of edge and taking two parameters. But since during declaration of we specify the types of the parameters the instead of specifying the arguments(as you did in your program), the program gives the mentinoed error.
To solve this replace that statement with:
edge minIncoming{ nullptr, NOPATH };
Now minIncoming is treated as an object of type edge and passing the two initializers.