C++ Custom Header File - Syntax Error C2061: identifier

544 Views Asked by At

I've been looking into Syntax Error C2061 for a while now, and I have come to understand that it is often caused by circular dependencies of header files. However, I believe I should've resolved this in my files yet I continue to have the issue.

Arc.h

#pragma once

#include <string>

using namespace std;

class Node;

class Arc
{
public:
    Arc(Node &p_destination, const string &p_mode);
    ~Arc();

private:
    string m_mode;
    Node* m_destination;
};

Node.h

#pragma once
#include <string>
#include <vector>

using namespace std;

class Arc;

class Node
{
public:
    Node(const string &p_name, const int &p_identifier, const float &p_latitude, const float &p_longitude);
    ~Node();

    void set_arcs(Arc* p_arc) { m_arcs.push_back(p_arc); } //Line that causes the error

private:
    std::vector<Arc*> m_arcs;
    //Other Private Variables removed

};

The header files have both been included in the corresponding cpp files. Any help on this matter will be greatly appreciated!

Edit: Full Error Message below

"Syntax Error: identifier 'Arc'"
2

There are 2 best solutions below

0
On BEST ANSWER

The problem is that the name "Arc" is already in use by a method in the global namespace. Either rename your class to an unused name or place it in a namespace which is not the global namespace.

1
On

You have a circular dependecy in you files. Arc depends on Node and Node depends on Arx. This cannot work, because you must include Arc in Node and also Node in Arc. Forward declaration helps here a little bit but you put a using inside the header file. You shouldn't do that because then your Node and Arc is inside std. Look here for further clarification. "using namespace" in c++ headers