我该如何解决它?在主函数中,当我试图让新节点有字符串数据时,它不能。错误消息是[错误]无法在分配中将'const std :: basic_string'转换为'int'。我该怎么做??C++错误:无法将const std :: basic_string <char>'转换为int中的int
template <typename value_type>
class node : public element
public :
value_type data;
node();
node (const value_type& T);
~node();
};
template <typename value_type>
node<value_type> :: node(const value_type& T)
{
type = 0;
intd= 0;
stringd = "";
if(typeid(T)==typeid(int))
{
type= 0;intd = T;
}
else if(typeid(T)==typeid(string))
{
type = 3;stringd = T;
}
this->left = NULL;
this->right = NULL;
this->data = T;
}
int main()
{
string s1 = "123";
node *n1 = new node<string>(s1);
return 0;
}
不要使用'typeid'为,请...'type = 0; intd = T;'仍然需要编译,即使条件是'false'。 – LogicStuff