0

HI
I am trying to combine(I think that is the word) a node and a class together.Could anybvody try to find the error I have thx

#include<iostream>
#include<conio.h>
using namespace std;
struct Node
{
  int data;
  Node* link;
};
typedef Node* NodePtr;
class Q
{
  public:
         void insert_data(int data);
         void display_data(int another_data);
  private:
          Node* head;
};
int main()
{
  NodePtr q;
  int number;
  cout<<"What is the number you would like to use: ";
  cin>>number;
  q.insert_data(number);
  q.display_data(number);
  
  getch();
  return 0;
}
void Q::insert_data(int data)
{
 cout<<"What number ould you like to use: ";
 head=new Node;
 cin>>head->data;
 head->link=NULL;
}
void Q::display_data(int another_data)
{
 cout<<head->data;
}

the problem is in line 28 that is:
28 C:\Documents and Settings\mauro\Desktop\c++\nodes - combine with class.cpp `insert_data' has not been declared

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Hamrick
0

NodePtr q;

That's the wrong type. I think you meant to declare an object of Q instead of a NodePtr...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.