Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

error: expected ',' or '…' before 'nullptr'

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading