错误 c2440 '='无法从 int * 转换为类型<T> *
Error c2440 '=' cannot convert from int * to Type<T> *
我在VS2015中得到以下错误。我不清楚我在模板中搞砸了什么。
任何指针(s)是真的很感激!
错误C2440 '=':无法从'int *'转换为'DNode *'
template<class Type>
class DNode <- *** THIS IS THE TYPE ***
{
public:
Type *next;
Type *previous;
Type value;
DNode(Type valueParam)
{
value = valueParam;
next = previous = NULL;
}
};
template<class T>
class DLinkedList
{
DNode<T> *head;
DNode<T> *tail;
public:
DLinkedList()
{
head = tail = NULL;
}
T pop_tail()
{
if (tail == NULL) return -1;
T value;
if (head == tail)
{
value = tail->value;
free(tail);
head = tail = NULL;
return value;
}
else
{
DNode<T> *ptr = tail;
value = tail->value;
tail = tail->previous; <-- *** THIS LINE THROWS ERR ***
tail->next = NULL;
free(ptr);
return value;
}
}
}
DNode::previous
的类型是Type*
,而不是DNode<Type>*
。
您可能希望将DNode::next
和DNode::previous
声明为DNode<Type>*
类型。
相关文章:
- 无法转换类型 C++
- 包含可变参数包的第一个可转换类型的别名的结构
- 将 std::conditional 与不可转换类型(原始与指针)一起使用
- 链接方法时出现转换类型错误
- 如何避免隐式转换类型
- 在多重继承场景中动态强制转换类型
- 编译器不支持的转换类型
- 错误调用功能无法转换类型
- 我想看到一个在整个后缀表达式的上下文中查找转换类型 id 的示例
- 对于动态类型为强制转换类型的对象,dynamic_cast失败
- 无法在初始化中转换类型
- 如何让"auto"转换类型
- 如何通过强制转换类型指针将字符数组转换为uint16_t
- 如何从新运算符+(Template类)返回具有转换类型的对象
- 带有模板的基于枚举的工厂无法转换类型
- 使用SWIG类型映射通过字符串转换类型
- 对于可转换类型,设计比循环依赖项更好
- SWIG不能正确转换类型定义
- 将类型转换扩展到可转换类型的对/元组
- 想要将字符数组的部分转换/类型转换为值