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: -
assign = searchTree(treeObj->root ,data1);
-
which is part of the following method -
void handleOneLine(string string1)
-
{
-
char * cstr, *p, *assign;
-
int counter;
-
string str (string1);
-
char data1, data2, data3;
-
-
cstr = new char [str.size()+1];
-
strcpy (cstr, str.c_str());
-
-
// cstr now contains a c-string copy of str
-
-
int count = 0;
-
p=strtok (cstr,",");
-
count++;
-
while (p!=NULL)
-
{
-
p=strtok(NULL,",");
-
if( count == 1 )
-
{
-
data1 = *p;
-
assign = searchTree(treeObj->root ,data1);
-
treeNodeObj->item = new TreeNode();
-
}
-
else if( count == 2 )
-
{
-
data2 = *p;
-
// treeNodeObj->setLeft(data2);
-
}
-
else if( count == 3 )
-
{
-
data3 = *p;
-
// treeNodeObj->setRight(data3);
-
}
-
count++;
-
if( count == 3 )
-
break;
-
}
-
-
delete[] cstr;
-
}
-
the searchTree method is below -
#include <iostream>
-
#include <fstream>
-
#include <string>
-
#include <queue>
-
#include <deque>
-
#include "TreeNode.h"
-
#include "Tree.h"
-
using namespace std;
-
-
Tree<char> *treeObj = NULL;
-
TreeNode<char> *treeNodeObj = NULL;
-
-
TreeNode<char>* searchTree(TreeNode<char> *cur, char nodeToAdd)
-
{
-
if(cur == NULL)
-
{
-
return NULL;
-
}
-
if(cur->IsSameNode(nodeToAdd))
-
{
-
return cur;
-
}
-
searchTree(cur->getLeft(), nodeToAdd);
-
searchTree(cur->getRight(), nodeToAdd);
-
}
-
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: -
#pragma once
-
#include <iostream>
-
#include <fstream>
-
#include <string>
-
#include <deque>
-
#include <queue>
-
using namespace std;
-
-
template <class T>
-
class TreeNode
-
{
-
public:
-
TreeNode<T>(T newItem);
-
~TreeNode<T>(void);
-
void setItem(T *newItem);
-
void setLeft(TreeNode *newLeft);
-
void setRight(TreeNode *newRight);
-
T getItem();
-
TreeNode<T>* getLeft();
-
TreeNode<T>* getRight();
-
bool IsSameNode(T c);
-
T item;
-
-
private:
-
TreeNode *left;
-
TreeNode *right;
-
};
-
-
-
template <class T>
-
TreeNode<T>::TreeNode(T newItem)
-
{
-
item = newItem;
-
left = null;
-
right = null;
-
}
-
-
template <class T>
-
TreeNode<T>::~TreeNode(void)
-
{
-
}
-
-
-
template <class T>
-
void TreeNode<T>::setItem(T *newItem)
-
{
-
// set methods
-
item = newItem;
-
}
-
-
template <class T>
-
void TreeNode<T>::setLeft(TreeNode *newLeft)
-
{
-
left = newLeft;
-
}
-
-
template <class T>
-
void TreeNode<T>::setRight(TreeNode *newRight)
-
{
-
right = newRight;
-
}
-
-
template <class T>
-
T TreeNode<T>::getItem()
-
{
-
// get methods
-
return item;
-
}
-
-
template <class T>
-
TreeNode<T>* TreeNode<T>::getLeft()
-
{
-
return left;
-
}
-
-
template <class T>
-
TreeNode<T>* TreeNode<T>::getRight()
-
{
-
return right;
-
}
-
-
template <class T>
-
bool TreeNode<T>::IsSameNode(T c)
-
{
-
return this->item == c;
-
}
-
3 1389
please feel free to ask me any qns or suggest any suggestions.. i am up for anything.. thanks :)
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: -
TreeNode<char>* assign;
-
assign = searchTree(treeObj->root ,data1);
-
or maybe you meant to assign to be of type char, and to use the TreeNode's item variable: -
char assign;
-
assign = searchTree(treeObj->root ,data1)->item;
-
Well, I hope this is somewhat helpful. Good luck.
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: -
TreeNode<char>* assign;
-
assign = searchTree(treeObj->root ,data1);
-
or maybe you meant to assign to be of type char, and to use the TreeNode's item variable: -
char assign;
-
assign = searchTree(treeObj->root ,data1)->item;
-
Well, I hope this is somewhat helpful. Good luck.
yup it was cheers! :)
Sign in to post your reply or Sign up for a free account.
Similar topics
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)...
|
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
|
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...
|
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) :...
|
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...
|
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...
|
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
...
|
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...
|
by: preeya |
last post by:
Hi,
I have written the following program:
-------------------------------------------------------------------------------------------------------------
1 #include <stdio.h>
2 #include...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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...
|
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...
| |