Defining a pointer to a list in C++

I'm new at C++ programming and I'm having troubles trying to define a pointer to a list. This is the code I'm trying to use:

list<int>* pl;

The error:

/home/julian/Proyectos Code::Blocks/pruebas/main.cpp|17|error: expected type-specifier before ‘list’|

Is it posible to define a pointer to a list? I need to have a function that returns a pointer to a list.

Thank you very much

Upvotes: 9

Views: 13245

Answers (3)

hatboyzero
hatboyzero

Reputation: 1937

Try the following:

std::list<int>* pl;

Upvotes: 1

cnicutar
cnicutar

Reputation: 182619

You have to include the list header and qualify the name list:

#include <list>

std::list<int> *p;

Alternatively:

using std::list;
list<int> *p;

Upvotes: 12

Mahesh
Mahesh

Reputation: 34625

list resides in std namespace. So try doing -

std::list<int>* pl; 

Upvotes: 3

Related Questions