STL syntax, container with reference to pointer
i want to create a container which contains references to pointers
1) Is this possible?
2) What is the syntax?
I imagine its
<T*&>
ie: std::stack< int*& > stack_;
but this just gives me errors "xme开发者_如何学运维mory: pointer to reference is illegal."
You cannot use references as the element type of a container, because there is no such thing as a reference object in C++.
What exactly are you trying to achieve? Why not simply use a std::stack<int>
?
Why don't you use std::stack<int*>
? What advantages do you see in using references to pointers? Or maybe, just std::stack<int>
should suffice your need? Have you tried them?
精彩评论