473,323 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Status of post: Unsolved!!! - type conversion problem that needs help C++

34
hi guys,
the error is as follows:
error C2440: '=' : cannot convert from 'TreeNode<T> *' to 'char *'
with
1> [
1> T=char
1> ]
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

i get this error from the following line of code:
Expand|Select|Wrap|Line Numbers
  1. assign = searchTree(treeObj->root ,data1);
  2.  
which is part of the following method
Expand|Select|Wrap|Line Numbers
  1. void handleOneLine(string string1)
  2. {
  3.     char * cstr, *p, *assign;
  4.     int counter;
  5.     string str (string1);
  6.     char data1, data2, data3;
  7.  
  8.     cstr = new char [str.size()+1];
  9.     strcpy (cstr, str.c_str());
  10.  
  11.     // cstr now contains a c-string copy of str
  12.  
  13.     int count = 0;
  14.     p=strtok (cstr,",");
  15.     count++;
  16.     while (p!=NULL)
  17.     {
  18.         p=strtok(NULL,",");
  19.         if( count == 1 )
  20.         {            
  21.             data1 = *p;
  22.             assign = searchTree(treeObj->root ,data1);
  23.             treeNodeObj->item = new TreeNode();
  24.         }
  25.         else if( count == 2 )
  26.         {
  27.             data2 = *p;
  28. //            treeNodeObj->setLeft(data2);
  29.         }
  30.         else if( count == 3 )
  31.         {
  32.             data3 = *p;
  33. //            treeNodeObj->setRight(data3);
  34.         }
  35.         count++;
  36.         if( count == 3 )
  37.             break;
  38.     }
  39.  
  40.     delete[] cstr; 
  41. }
  42.  
the searchTree method is below
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <queue>
  5. #include <deque>
  6. #include "TreeNode.h"
  7. #include "Tree.h"
  8. using namespace std;
  9.  
  10. Tree<char> *treeObj = NULL;
  11. TreeNode<char> *treeNodeObj = NULL;
  12.  
  13. TreeNode<char>* searchTree(TreeNode<char> *cur, char nodeToAdd)
  14. {
  15.     if(cur == NULL) 
  16.     {
  17.         return NULL;
  18.     }
  19.     if(cur->IsSameNode(nodeToAdd))
  20.     {
  21.         return cur;
  22.     }
  23.     searchTree(cur->getLeft(), nodeToAdd);
  24.     searchTree(cur->getRight(), nodeToAdd);
  25. }
  26.  
could you please help me with this?
i will reply within 5 mins so plz do check back if u require anything else e.g. code or a qn answered.
thanks :)

i have included the TreeNode file below just in case:
Expand|Select|Wrap|Line Numbers
  1. #pragma once
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. #include <deque>
  6. #include <queue>
  7. using namespace std;
  8.  
  9. template <class T>
  10. class TreeNode
  11. {
  12.     public:
  13.         TreeNode<T>(T newItem);
  14.         ~TreeNode<T>(void);
  15.         void setItem(T *newItem);
  16.         void setLeft(TreeNode *newLeft);
  17.         void setRight(TreeNode *newRight);
  18.         T getItem();
  19.         TreeNode<T>* getLeft();
  20.         TreeNode<T>* getRight();
  21.         bool IsSameNode(T c);
  22.         T item;
  23.  
  24.     private:
  25.         TreeNode *left;
  26.         TreeNode *right;
  27. };
  28.  
  29.  
  30. template <class T>
  31. TreeNode<T>::TreeNode(T newItem)
  32. {
  33.     item = newItem;
  34.     left = null;
  35.     right = null;
  36. }
  37.  
  38. template <class T>
  39. TreeNode<T>::~TreeNode(void)
  40. {
  41. }
  42.  
  43.  
  44. template <class T>
  45. void TreeNode<T>::setItem(T *newItem) 
  46. {
  47.     // set methods
  48.     item = newItem;
  49. }
  50.  
  51. template <class T>
  52. void TreeNode<T>::setLeft(TreeNode *newLeft) 
  53. {
  54.     left = newLeft;
  55. }
  56.  
  57. template <class T>
  58. void TreeNode<T>::setRight(TreeNode *newRight) 
  59. {
  60.     right = newRight;
  61. }
  62.  
  63. template <class T>
  64. T TreeNode<T>::getItem()
  65. {
  66.     // get methods
  67.     return item;
  68. }
  69.  
  70. template <class T>
  71. TreeNode<T>* TreeNode<T>::getLeft() 
  72. {
  73.     return left;
  74. }
  75.  
  76. template <class T>
  77. TreeNode<T>* TreeNode<T>::getRight() 
  78. {
  79.     return right;
  80. }
  81.  
  82. template <class T>
  83. bool TreeNode<T>::IsSameNode(T c)
  84. {
  85.     return this->item == c;
  86. }
  87.  
Sep 6 '08 #1
3 1389
slizorn
34
please feel free to ask me any qns or suggest any suggestions.. i am up for anything.. thanks :)
Sep 6 '08 #2
boxfish
469 Expert 256MB
Hi,
I'm not sure this is helpful, but here it is anyway.
Your compiler is complaining because the searchTree function returns a TreeNode<char>*, and you can't assign that to a variable of type char*.
I didn't look at your code very carefully, but maybe you meant assign to be of type TreeNode<char>*, like this:
Expand|Select|Wrap|Line Numbers
  1. TreeNode<char>* assign;
  2. assign = searchTree(treeObj->root ,data1);
  3.  
or maybe you meant to assign to be of type char, and to use the TreeNode's item variable:
Expand|Select|Wrap|Line Numbers
  1. char assign;
  2. assign = searchTree(treeObj->root ,data1)->item;
  3.  
Well, I hope this is somewhat helpful. Good luck.
Sep 6 '08 #3
slizorn
34
Hi,
I'm not sure this is helpful, but here it is anyway.
Your compiler is complaining because the searchTree function returns a TreeNode<char>*, and you can't assign that to a variable of type char*.
I didn't look at your code very carefully, but maybe you meant assign to be of type TreeNode<char>*, like this:
Expand|Select|Wrap|Line Numbers
  1. TreeNode<char>* assign;
  2. assign = searchTree(treeObj->root ,data1);
  3.  
or maybe you meant to assign to be of type char, and to use the TreeNode's item variable:
Expand|Select|Wrap|Line Numbers
  1. char assign;
  2. assign = searchTree(treeObj->root ,data1)->item;
  3.  
Well, I hope this is somewhat helpful. Good luck.

yup it was cheers! :)
Sep 6 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Mark Oliver | last post by:
Hi, I want to put a type conversion in my class, but I don't want the conversion to be usable in a passed parameter because it makes no sense. class cData { string s; public cData(string s)...
1
by: Joe HM | last post by:
Hello - I have two Enums for which I would like to define type conversions ... Public Enum eA A2 = 0 A2 = 1 End Enum Public Enum eB B1 = 2
3
by: =?ISO-8859-1?Q?S=F8ren?= | last post by:
Hi Guys I'm still trying to learn C++, and it´s going im the right direction. The only thing that keeps make me banging my head againts the wall, is when I have a variable of some sort, and need...
4
by: zaeminkr | last post by:
I got a good answer here I have still confusing part. I have two very simple classes class DRect { private : double x0, y0, x1, y1; public : DRect(double a, double b, double c, double d) :...
2
by: algatt | last post by:
Hello, I am trying to compile the TPIE files but there is a file that's constantly giving errors about the templates. I am using gcc 3.4.5 on Eclipse using Windows XP. The following is the code of...
11
by: 1230987za | last post by:
Hi, I am totally confused now about C type conversion. I know that C does some implicit type conversion like integer promotion and float to double. I imagine that such conversion must keep the...
2
by: java | last post by:
Hi: There is an introductory diagram for those confused by javascript type wrangling (i.e., runtime type conversion by the javascript interpreter). http://mollypages.org/misc/jstypes.mp ...
1
by: sanusultan | last post by:
Hello everyone, I'm working on my project I have written the code for my project in c. I am getting an error: E2110 Incompatible type conversion Here is what i have: my code: code...
10
by: preeya | last post by:
Hi, I have written the following program: ------------------------------------------------------------------------------------------------------------- 1 #include <stdio.h> 2 #include...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.