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 .

See also  How HealthStream Learning Center Supports Healthcare Education and Compliance
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist