simple namespace question

M

michael

Hi all,

why if I can use

std::vector<int>::iterator variable;

can I not use

using std::vector<int>::iterator;

to save typing the std::vector<int>:: each time I use it?
I have a text which has the 'using' statement in it, but when I compile I
get errors like "std::vector<int, std::allocator<int>> is not a namespace".
I don't understand why, if someone could explain it I would be gratefull.

Thanks for your help

Regards

Michael
 
G

Gianni Mariani

michael said:
Hi all,

why if I can use

std::vector<int>::iterator variable;

can I not use

using std::vector<int>::iterator;

That's illegal. This is legal.

typedef std::vector<int>::iterator iterator;
 
I

Ian Collins

michael said:
Hi all,

why if I can use

std::vector<int>::iterator variable;

can I not use

using std::vector<int>::iterator;

to save typing the std::vector<int>:: each time I use it?
I have a text which has the 'using' statement in it, but when I compile I
get errors like "std::vector<int, std::allocator<int>> is not a namespace".
I don't understand why, if someone could explain it I would be gratefull.
The error says it all. You can only use a using directive with a
namespace. Use a typedef instead.
 
M

michael

Ian Collins said:
The error says it all. You can only use a using directive with a
namespace. Use a typedef instead.

Thanks for the help Ian,

I'm still a bit confused though. What exactly makes
std::vector<int>::iterator not a namespace when for example std::endl is?
What is it that determines whether something is a namespace or not?

thanks for the help

regards

Michael
 
I

Ian Collins

*Please* don't quote signatures.
Thanks for the help Ian,

I'm still a bit confused though. What exactly makes
std::vector<int>::iterator not a namespace when for example std::endl is?
What is it that determines whether something is a namespace or not?
Using std::vector or using std::cout are legal. Using only works with a
namespace, or an object or value from a namespace, not a type from a
class in a namespace. std::vector<int>::iterator goes one step too far.
Use a typedef.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top