473,408 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

simple namespace question

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
Apr 18 '07 #1
4 1245
michael wrote:
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;
Apr 18 '07 #2
michael wrote:
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.

--
Ian Collins.
Apr 18 '07 #3

"Ian Collins" <ia******@hotmail.comwrote in message
news:58**************@mid.individual.net...
michael wrote:
>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.

--
Ian Collins.
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
Apr 19 '07 #4
michael wrote:
"Ian Collins" <ia******@hotmail.comwrote in message
news:58**************@mid.individual.net...
>>michael wrote:
>>>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.
*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.

--
Ian Collins.
Apr 19 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: lokman | last post by:
Hi, In the following code, can someone tell me the difference between *p++ and p++ ? I can see both achieve the same result. Thanks a lot !
7
by: Mark Prenter | last post by:
Hi all, I'm fairly new to .NET and I haven't done much in C++ before, nothing complex anyway, but I have a pretty good understanding of programming in general. What I'm trying to do is create a...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
3
by: Katie S | last post by:
I have a method that takes a string, formats it and returns it I want to use this in multiple ASP.NET pages, by putting it in a namespace and using that in each asp.net page What I don't...
7
by: SL | last post by:
Could someone direct to a simple explanation of how to use MS Visual Studio 2003 to design .aspx code? This code works if pasted into notepad and run as an .aspx file: <%@ Import...
6
by: Paul | last post by:
Hi All, Framework 1.1 listbox control unable to DataBind I've been googling for an answer to this query that appears quite a lot, but none, it seem, answers my problem directly. I am...
3
by: Marco T. | last post by:
Hi all, why the former code fragment works and the latter doesn't? ============= //CORRECT CODE: namespace ciao { class A{};
3
by: Chrism2671 | last post by:
I'm new to XSLT/XML and I have a very simple, quick question. i've been trying to convert simple xml files into CSV files and have made a simple XSLT template using the w3 tutorials, but it doesn't...
3
by: Steven Edison | last post by:
I have a split container on my form, from within one of them I wish to reach the main from of the app. I'm having problems with the headers and namespaces. I want something like this: ...
4
by: =?Utf-8?B?SmFtZXMgUGFnZQ==?= | last post by:
Am i missing somthing simple? I can't access any of the profile names in my code behind i.e; textBox1.text = Profile.test = "some text" here's the web.config: <?xml version="1.0"?> ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.