aCuria
aCuria

Reputation: 7205

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

Upvotes: 0

Views: 349

Answers (2)

Sarfaraz Nawaz
Sarfaraz Nawaz

Reputation: 361472

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?

Upvotes: 0

fredoverflow
fredoverflow

Reputation: 263128

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

Upvotes: 4

Related Questions