这篇博客的源起是我下面的一段代码
#include <bits/stdc++.h>
using namespace std;
int main(){
priority_queue<long long> que;
// some operations on que
que = {};
// some operations on que
return 0;
}
其中 que = {}
相当于 que.clear();
(std::priority_queue
并没有 clear()
方法)。
hahah
然而编译器对这个语句给出了一个警告:
(g++ 6.3.0:g++ -Wall -std=c++14
)
In function 'int main()':
7:12: warning: converting to 'std::priority_queue<long long int>' from initializer list would use explicit constructor 'std::priority_queue<_Tp, _Sequence, _Compare>::priority_queue(const _Compare&, _Sequence&&) [with _Tp = long long int; _Sequence = std::vector<long long int, std::allocator<long long int> >; _Compare = std::less<long long int>]'
que = {};
^
7:12: note: in C++11 and above a default constructor can be explicit