0

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 "xmemory: pointer to reference is illegal."

2 Answers 2

4

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>?

Sign up to request clarification or add additional context in comments.

2 Comments

I want a stack of pointers. When the pointers in the stack are modified, the original pointer that was passed into the stack should be modified too. I guess the solution is to use a stack of pointers to pointers.
Pointer to pointers are hardly ever the right solution... :-(
0

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.