cpp*_*ser 5 c++ linked-list curly-braces copy-constructor singly-linked-list
我是面向对象的C++的新手,我正在尝试以这种方式为链表创建一个构造函数:
List.h中的某个地方我们有这个:
struct Node
{
int data;
Node *next;
};
Run Code Online (Sandbox Code Playgroud)
然后在main.cpp中,我希望能够构建一个这样的列表:
int main()
{
List A({1,2,3,4,5,6});// I want the amount of numbers to indicate the size of
//the list and the numbers to go into each node in order
return 0;
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,我可以制作这样的构造函数吗?如果是这样呢?我必须使用模板吗?我试图在SO中找到这样的问题,但它们都包含模板,我还没有学到.如果我可以让我的构造函数执行此操作,是否可以在不使用模板的情况下执行此操作?