一些关于我如何初始化我的私有(private)类(class)成员的事情。警告消息没有意义......我试图查看它们是否被串联......但它们似乎并没有......这就是 Eclipse 所说的。抱歉,我无法更好地格式化它。
编译器信息如下:
Description Resource Path Location Type
'sl_list<int>::node_1* sl_list<int>::head' test_a line 13 C/C++ Problem
when initialized here test_a line 18 C/C++ Problem
'sl_list<int>::count' will be initialized test_a line 14 C/C++ Problem
相关代码——调用linked_list
#include "c_include_list.cpp"
#include "c_linked_list.cpp"
using namespace std;
int main() {
cout << "sl_list" << endl;
sl_list<int> sl_list_object;
}
相关代码-linked_list实现
template <class T1> class sl_list
{
private:
class node_1
{
public:
T1 data;
node_1 *next;
node_1(T1 data, node_1 *next = NULL) : data(data), next(next) {}
};
node_1 *head; // line 13
int count; // line 14
public:
sl_list() : count(0), head(NULL){} // line 18
最佳答案
答案很简单:按照声明的顺序初始化成员。
sl_list() : head(NULL), count(0){}
默认情况下,这只是一个警告,因此 Eclipse 可能向编译器提供了 -Wall 和 -Werror 标志。
关于c++ - Eclipse 给出 MingGW 没有的编译器警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8113346/