initializer_list有什么作用? [英] What does initializer_list do?
问题描述
我目前的任务是为我的教授提供给我们的特殊自定义课程创建定义;我从未见过使用initializer_list的情况,我的教授也没有看过它。
I'm currently tasked with creating a definition for a special custom class my professor provided to us; I've never seen initializer_list in use, nor did my professor go over it. What exactly does it do?
template<class T>
LinkedQueue<T>::LinkedQueue(const std::initializer_list<T>& il) {
}
我必须定义构造函数,这将由我自己完成。我只想知道此参数的作用。另外,我的编译器不断告诉我找不到std :: initializer_list成员声明。我已经使用#include导入了它,但是问题仍然存在。
I have to define the constructor, which I will do on my own. I just want to know what this parameter does. Also, my compiler keeps telling me that std::initializer_list member declaration is not found. I've imported it using #include but the issue is still here.
推荐答案
它允许您使用{}来初始化LinkedQueue。 。
,如
It allows you to initalize your LinkedQueue with {}. as in
LinkedQueue<char> theQueue = {'a','b','c','d','e','f','g','h' };
以及其他内容,详细说明此处关于它及其用途的页面。
as well as other things, detailed here on a page about it and it's uses.
这篇关于initializer_list有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!