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 3281194
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:47:19+00:00 2026-05-17T19:47:19+00:00

At the consturctor Node = new Node[numberOfNodes]; and Edge = new Edge[numberOfEdges]; gives identifier

  • 0

At the consturctor Node = new Node[numberOfNodes]; and Edge = new Edge[numberOfEdges]; gives identifier error? what’s the wrong with it ?

typedef struct node
{
 int id;
 int x;
 int y;
} Node;

typedef struct edge
{
 int id;
 Node node1;
 Node node2;
} Edge;

class graph
{
private:
 int numberOfNodes;
 int numberOfEdges;
 int *Node;
 int *Edge;

public:
 graph(int nodes, int edges)
 {
  numberOfNodes = nodes;
  numberOfEdges = edges;
  Node = new Node[numberOfNodes];
  Edge = new Edge[numberOfEdges];
 }
  • 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-17T19:47:20+00:00Added an answer on May 17, 2026 at 7:47 pm

    You have various variable name conflicts, including a conflict between your variable declaration int* Node, and the typedef Node. Also, you declare your array of nodes as type int* when it should be type Node*. You do the same with Edge. Try the following instead:

    class graph
    {
        private:
        int numberOfNodes;
        int numberOfEdges;
        Node* nodes_;
        Edge* edges_;
    
        public:
    
        graph(int num_nodes, int num_edges)
        {
            numberOfNodes = num_nodes;
            numberOfEdges = num_edges;
            nodes_ = new Node[numberOfNodes];
            edges_ = new Edge[numberOfEdges];
        }
    };
    

    Also, just for the future, the typedef struct { } idiom is really unnecessary in C++. It’s main purpose was so that C programmers wouldn’t need to constantly have to prefix their struct variables with the word struct. But in C++ this isn’t necessary, so there’s generally no real reason to say typedef struct node { ... } Node; when you can just say struct Node { ... };. See here for more information.

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

Sidebar

Related Questions

#include <iostream> using namespace std; struct Term; struct Node; typedef Term* termPtr; typedef Node*
I have a class class Node { public: int value; Node * next; Node();
I have a template class btree and have defined a struct Node in the
I am trying to cast a list of objects within a consturctor for a
I have a graph class with Node's, where each Node can connect to others:
So for my assignment, I am supposed to implement a Node class that just
I'm new to Java and I am doing a homework on constructing Decision Trees.
Answer: It turns out I had neglected to use the new keyword when creating
I am trying to initialize a node array in the node class, they are
I'm writing some C++ code for a simple Node class. This is basically a

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.