0

Hi
Why is that wrong

#include<iostream>
#include<conio.h>
using namespace std;
struct Node
{
  char your_name;
  Node *link;
};
typedef Node* NodePtr;
class Q
{
  public:
         Q();
         void get_input( );
         void display_input( );
  private:
          NodePtr head;
};
int main()
{
  Q name;
  char your_name;
  cout<<"What is your name: ";
  name.get_input( );
  name.display_input( );
  
  getch();
  return 0;
}
Q::Q()
{
 cout<<"Your name is initialize to '/0'"<<endl;
 head=NULL;
}
void Q::get_input( )
{
  char temp[50];
  cin>>temp;   
  head= new Node;
  strcpy(head->your_name,temp);
  head->link=NULL;
}
void Q::display_input( )
{
  cout<<"Your name is equall to: ";
  cout<<head->your_name;
}

tghe error I have is :
46 C:\Documents and Settings\mauro\Desktop\c++\nodes- another simple example using an array of characters.cpp invalid conversion from `char' to `char*'

thx

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

line 7: your_name is a single character and you are attempting to use it as if it were a character array in line 41. Change the declaration in line 7 to be a character array.

Or, better yet, since this is a C++ program change it to be std::string class object, assuming your instructor will let you do that.

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.