Hi All,
I've wasted heaps of time today trying to get some code I copied from a text
to compile. I have cut it down to the following couple of lines which
demonstrate the core of the problem:
#include <iostream>
#include <list>
//using namespace std;
using std::cout;
using std::cin;
using std::list;
using std::list<int>::iterator;
int main(){
list<int myList;
iterator<intit;
return 0;
}
if I try to compile it as above I get :
:7: error: `std::list<int, std::allocator<int' is not a namespace
Why?
if I remove the comment marks from the 'using namespace std' and comment out
all the specific 'using's (to try and get round the above) I get:
:12: error: wrong number of template arguments (1, should be 5)
Where did the 5 instead of 1 come from? <sigh>
Thanks for your help
Michael 5 2265
if I try to compile it as above I get :
:7: error: `std::list<int, std::allocator<int' is not a namespace
Why?
My guess std::list<int, std::allocator<int is a class name not a
namespace name. But here some C++ specialist must say something.
if I remove the comment marks from the 'using namespace std' and comment out
all the specific 'using's (to try and get round the above) I get:
:12: error: wrong number of template arguments (1, should be 5)
Where did the 5 instead of 1 come from? <sigh>
#include <iostream>
#include <list>
int main(){
std::list<int myList;
std::list<int>::iterator it;
return 0;
}
Compiles.
In C++ FAQ lite is quite long entry about why 'using something', and
'using namespace something' is evil.
My rule of the thumb is not to use it. I spend time typing, and I
spend less time finding errors (but I'm not a pro progammer).
Hope it helps.
* Michael:
Hi All,
I've wasted heaps of time today trying to get some code I copied from a text
to compile. I have cut it down to the following couple of lines which
demonstrate the core of the problem:
#include <iostream>
#include <list>
//using namespace std;
using std::cout;
using std::cin;
using std::list;
using std::list<int>::iterator;
int main(){
list<int myList;
iterator<intit;
return 0;
}
if I try to compile it as above I get :
:7: error: `std::list<int, std::allocator<int' is not a namespace
Why?
A 'using' declaration only applies to something directly in a namespace,
not things in classes. std::list<intis a class, not a namespace. You
cannot use 'using' for things in std::list<int>.
if I remove the comment marks from the 'using namespace std' and comment out
all the specific 'using's (to try and get round the above) I get:
:12: error: wrong number of template arguments (1, should be 5)
Where did the 5 instead of 1 come from? <sigh>
You haven't shown the code producing that error message, but most
probably it's because of your use of 'iterator', which isn't a template.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Alf P. Steinbach wrote:
* Michael:
>:12: error: wrong number of template arguments (1, should be 5) Where did the 5 instead of 1 come from? <sigh>
You haven't shown the code producing that error message, but most
probably it's because of your use of 'iterator', which isn't a template.
Yes, it is ;-)
Without all the using directives, the compiler is probably thinking of
namespace std {
template<class Category, class T, class Distance = ptrdiff_t,
class Pointer = T*, class Reference = T&>
struct iterator {
typedef T value_type;
typedef Distance difference_type;
typedef Pointer pointer;
typedef Reference reference;
typedef Category iterator_category;
};
}
Markus
On Mar 12, 10:40 am, "Michael" <michael5...@yahoo.comwrote:
using std::list<int>::iterator;
typedef std::list<int>::iterator not_so_cool_idea;
=^) ja******@gmail.com wrote:
In C++ FAQ lite is quite long entry about why 'using something', and
'using namespace something' is evil.
Honestly, I disagree with this entry in the FAQ. See this discussion
for more details: http://groups.google.com/group/comp....24e006d2881a9/
In a nutshell, using directives and using declarations are OK if you can
control the scope in which they're applied. For example, don't use them
in header files, since it will affect anyone who includes your header.
But for localized use in implementation files, they can actually enhance
the readability of the code.
As Daniel T. mentions in the above-cited thread, see "C++ Coding
Standards" by Sutter and Alexandrescu for more information.
--
Marcus Kwok
Replace 'invalid' with 'net' to reply This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tim Tyler |
last post by:
PHP puts most of its functions into a big flat global namespace.
That leads to short function names - but creates a namespace
minefield for programmers.
Lots of the functions are legacies from...
|
by: dimension |
last post by:
Hi,
in visual studio 2005 beta, when i type "using System.Web." no code complete
helper pops up. Similarly, when typing "using System.Net." i do not see an
HttpWebRequest in the list that pops...
|
by: Enos Meroka |
last post by:
Hallo,
I am a student doing my project in the university.. I have been trying
to compile the program using HP -UX aCC compiler, however I keep on
getting the following errors.
...
|
by: Calum Grant |
last post by:
In older C++ computer books, you'll often see
using namespace std;
even in my 1996 copy of Stroustrup. Nowadays, it seems to be considered
better to qualify names to make it clearer what...
|
by: SpOiLeR |
last post by:
Why doesn't following code compile? Problem line is commented in code.
---------------------- Cut here-------------------------------
#include <iostream>
#include <list>
#include <string>
...
|
by: Natan |
last post by:
When you create and aspx page, this is generated by default:
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Configuration;
using System.Text;
using...
|
by: Steven Bolard |
last post by:
Hello,
I am trying to port my .net 1.1 application to 2.0. I am using vs2005. I am
trying to get my webservices to run and although i can compile them and and
get wsdl and service descriptions...
|
by: michael.d.pedersen |
last post by:
Hello group,
I am new to Visual C++ 8 and have a seemingly trivial problem using
namespaces. The scenario: I have two classes, TestClass1 and
TestClass2, in the namespace Test. I would like to...
|
by: ThunderMusic |
last post by:
Hi,
I have many classes a user may need to call methods on my webservice. Some
classes are "published" and some are not... I mean, when we do a Web
reference from another project, we don't have...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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,...
|
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |