用Dev-Cpp编译时出现的警告问题
我写的一个小程序里面,发现只要是写了如下的代码:vector<Student_info> students, fails;
......
fails = extract_fails(students);
......
fails = extract_fails(students);
用Dev-Cpp(Gcc3.4.5)编译时,就会提示如下警告(注,是加-Wall参数才会出现的警告,不加则没有):
C:\Dev-Cpp\include\c++\3.4.5\bits\stl_vector.h In member function `std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = Student_info, _Alloc = std::allocator<Student_info>]':
715 C:\Dev-Cpp\include\c++\3.4.5\bits\stl_vector.h [Warning] '__result' might be used uninitialized in this function
82 C:\Dev-Cpp\include\c++\3.4.5\bits\stl_uninitialized.h [Warning] '__cur' might be used uninitialized in this function
82 C:\Dev-Cpp\include\c++\3.4.5\bits\stl_uninitialized.h [Warning] '__cur' might be used uninitialized in this function
715 C:\Dev-Cpp\include\c++\3.4.5\bits\stl_vector.h [Warning] '__result' might be used uninitialized in this function
82 C:\Dev-Cpp\include\c++\3.4.5\bits\stl_uninitialized.h [Warning] '__cur' might be used uninitialized in this function
82 C:\Dev-Cpp\include\c++\3.4.5\bits\stl_uninitialized.h [Warning] '__cur' might be used uninitialized in this function
一旦我将代码改写成如下的形式:
vector<Student_info> students;
......
vector<Student_info> fails(extract_fails(students));
......
vector<Student_info> fails(extract_fails(students));
就不会警告了,这个是什么原因造成的呢?