devxlogo

A Reference to a Reference is Illegal

A Reference to a Reference is Illegal

What is wrong with this code snippet?

 #include #include using std::string;using std::list;class Node {/*..*/};int main(){  list  ln; //error}

If you try to compile this example, your compiler will issue numerous compilation errors. The problem is that list has member functions that take or return T&. In other words, the compiler transforms to . Because a reference to a reference is illegal in C++, the program is ill-formed. As a rule, you should instantiate templates in the form of list and never as list .

devx-admin

Share the Post: