c++namespacestoken-name-resolution

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


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'"

Solution

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