Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1100401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:52:31+00:00 2026-05-17T00:52:31+00:00

Header file is graph.h #ifndef _GRAPH_H_ #define _GRAPH_H_ #include <map> #include <vector> using namespace

  • 0

Header file is “graph.h”

#ifndef _GRAPH_H_
#define _GRAPH_H_

#include <map>
#include <vector>

using namespace std;

template <class T>
class VERTEX
{
public:
    VERTEX(T inVertex): m_vertex(inVertex), m_visited(false){}
    ~VERTEX(){}
private:
    T m_vertex;
    bool m_visited;
};

template <class T>
class GRAPH
{
public:
    GRAPH() {}
    ~GRAPH(){}
    typedef VERTEX<T> GRAPHVERTEX;
    typedef vector<GRAPHVERTEX> ADJLIST;
    typedef map<GRAPHVERTEX, ADJLIST> GRAPHMAP;

    void insert(GRAPHVERTEX inSRC, GRAPHVERTEX inDST)
    {
        GRAPHMAP::iterator itr = m_graph.find(inSRC);
    }

private:
    GRAPHMAP m_graph;
};

#endif

And test file is

#include "graph.h"

int main( int argc, char**argv)
{
    GRAPH<int> *G = new GRAPH<int>();
    G->insert(VERTEX<int>(0), VERTEX<int>(2));
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:52:32+00:00Added an answer on May 17, 2026 at 12:52 am

    There are two problems.

    First you have to qualify the dependent type in insert:

    void insert(GRAPHVERTEX inSRC, GRAPHVERTEX inDST)
    {
        typename GRAPHMAP::iterator itr = m_graph.find(inSRC);
    }
    

    Second, you need a < operator for your vertex class. In the public section of VERTEX add this:

    bool operator<(const VERTEX<T>& right) const { return m_vertex < right.m_vertex; }
    

    As a matter of style note that in C++ ALL CAPS names are usually reserved for constants. Vertex would be a much more normal name for your class. Also note that having using namespace in a header can have many undesired and unpredictable results depending on include order and should be completely avoided.

    EDIT: At least when I compiled this with g++ the first error I got was regarding GRAPHMAP::iterator. When a compiler sees an identifier that could be treated as a variable or a type, it choose to interpret it as a variable by default, but then at a later point discovered it was actually a type. You tell the compiler that it’s really a type by using the typename keyword.

    The second thing to note is that map is an ordered container and as such you need to either pass in a comparison function OR provide a < operator for the key of the map. Since VERTEX is the map key, I set up an operator< so that the objects can be sorted and have an order maintained. You may need to adjust the comparison operator as your VERTEX class evolves.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

//// header file #ifndef _SECTION_ #define _SECTION_ #include <map> #include Employee.h using namespace std;
Header file #ifndef IREADER_H #define IREADER_H #include <iostream> class iReader { public: iReader(); iReader(istream
in header file I have defined the following function #ifndef OS_H #define OS_H #include
Consider having the following header file (c++): myclass.hpp #ifndef MYCLASSHPP_ #define MYCLASSHPP_ namespace A
I have the following header file: #ifndef CLASSES_H #define CLASSES_H class Mouse // Handles
I have the header file testcode.h #ifndef TESTCODE_H #define TESTCODE_H class A { public:
Header file: // pe10-8arr.h -- header file for a simple list class #ifndef SIMPLEST_
I have a header file like this: #ifndef __GEN_NOTE_MARKERS_TO_DEVELOPERS_HPP__ #define __GEN_NOTE_MARKERS_TO_DEVELOPERS_HPP__ #ifdef _DEBUG //
This is my header file: /** * Job.h * **/ #ifndef JOB_ #define JOB_
I have a function (assign) in a class (graph) in a header file. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.