[英]error C2664: cannot convert parameter 1 from 'int' to 'int []'
[英]error C2664 :cannot convert argument from 'Node<int>* ' to 'int'
Node.h:
#include <memory>
using namespace std;
template <typename T>
class Node
{
private:
T m_Data;
shared_ptr<Node<T>> pre_node,next_node;
public:
Node(T iData, Node* pre_ptr = nullptr, Node* next_ptr = nullptr)
:m_Data(iData),pre_node(make_shared<Node>(pre_ptr)),
next_node(make_shared<Node>(next_ptr))
};
main.cpp中
#include "Node.h"
int main()
{
Node<int> head(1);
system("pause");
return 0;
}
嘗試運行代碼時出錯:
error C2664: 'Node<int>::Node(const Node<int> &) throw()' : cannot convert argument 1
from 'Node<int> *' to 'int'
有人可以解釋問題以及糾正它的方法嗎?
問題很可能是對std::make_shared
的調用:
make_shared<Node>(next_ptr)
這里,參數應該是一個Node
或者可以用來構造一個的東西(例如,一個T
或者特別是在你的情況下,一個int
。)你傳遞一個Node*
。
不要傳遞Node*
。 傳遞int
或Node
。 或者將構造函數更改為以下內容:
Node(T iData, shared_ptr<Node> pre_ptr = nullptr, shared_pre<Node> next_ptr = nullptr)
: m_Data(iData),
pre_node(pre_ptr),
next_node(next_ptr)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.