In file included from prg6_3.cpp:6:
list1.hpp:6: error: parse error before `>' token
list1.hpp: In function `void insert_order(...)':
list1.hpp:9: error: parse error before `>' token
list1.hpp:10: error: parse error before `>' token
list1.hpp: At global scope:
list1.hpp:23: error: parse error before `>' token
list1.hpp: In function `void remove_duplicates(...)':
list1.hpp:28: error: parse error before `>' token
list1.hpp:29: error: parse error before `>' token
Ummm...I'd rather explicitely resolve the scope in this case (that is prefix with std:: as needed) because the code above is likely to reside in a header. The 'using' bloats 'list' into the global namespace, which I find rather unpretty.
Ummm...I'd rather explicitely resolve the scope in this case (that is prefix with std:: as needed) because the code above is likely to reside in a header. The 'using' bloats 'list' into the global namespace, which I find rather unpretty.
Ahh... that's right, thanks dude . I'll just post all of my source files as well as the error output, it should give a better view of what I'm trying to do.
Errors:
Code:
In file included from prg6_3.cpp:6:
list1.hpp:5: error: parse error before `>' token
list1.hpp: In function `void insert_order(...)':
list1.hpp:8: error: parse error before `>' token
list1.hpp:9: error: parse error before `>' token
list1.hpp: At global scope:
list1.hpp:22: error: parse error before `>' token
list1.hpp: In function `void remove_duplicates(...)':
list1.hpp:27: error: parse error before `>' token
list1.hpp:28: error: parse error before `>' token
In file included from prg6_3.cpp:7:
util.hpp: At global scope:
util.hpp:5: error: parse error before `&' token
util.hpp: In function `void write_list(...)':
util.hpp:7: error: parse error before `>' token
prg6_3.cpp: In function `int main()':
prg6_3.cpp:21: error: no matching function for call to `insert_order(
std::list<int, std::allocator<int> >&, int&)'
prg6_3.cpp:26: error: no matching function for call to `write_list(
std::list<int, std::allocator<int> >&)'
prg6_3.cpp:29: error: no matching function for call to `remove_duplicates(
std::list<int, std::allocator<int> >&)'
prg6_3.cpp:33: error: no matching function for call to `write_list(
std::list<int, std::allocator<int> >&)'
I only looked at list1.hpp. There's no include directive, and no declaration of the class 'list'. The compiler doesn't know what a "list" is, so you get these errors.
Add '#include <list>' to the top of 'list1.hpp'; and replace all instances of "list" with "std::list". If you are trying to use the STL list, of course. Otherwise, just include your declaration of "list".
I only looked at list1.hpp. There's no include directive, and no declaration of the class 'list'. The compiler doesn't know what a "list" is, so you get these errors.
Add '#include <list>' to the top of 'list1.hpp'; and replace all instances of "list" with "std::list". If you are trying to use the STL list, of course. Otherwise, just include your declaration of "list".
Viggy
Yes, I am trying to use STL.
Here is what I have for list1.hpp. I did as you instructed, but I still got approximately as many errors.
In file included from prg6_3.cpp:6:
list1.hpp: In function `void insert_order(std::list<T, std::allocator<_CharT>
>&, const T&)':
list1.hpp:10: warning: `std::list<T, std::allocator<_CharT> >::iterator' is
implicitly a typename
list1.hpp:10: warning: implicit typename is deprecated, please see the
documentation for details
list1.hpp:11: warning: `std::list<T, std::allocator<_CharT> >::iterator' is
implicitly a typename
list1.hpp:11: warning: implicit typename is deprecated, please see the
documentation for details
list1.hpp: In function `void remove_duplicates(std::list<T,
std::allocator<_CharT> >&)':
list1.hpp:29: warning: `std::list<T, std::allocator<_CharT> >::iterator' is
implicitly a typename
list1.hpp:29: warning: implicit typename is deprecated, please see the
documentation for details
list1.hpp:30: warning: `std::list<T, std::allocator<_CharT> >::iterator' is
implicitly a typename
list1.hpp:30: warning: implicit typename is deprecated, please see the
documentation for details
In file included from prg6_3.cpp:7:
util.hpp: At global scope:
util.hpp:5: error: parse error before `&' token
util.hpp: In function `void write_list(...)':
util.hpp:7: error: parse error before `>' token
prg6_3.cpp: In function `int main()':
prg6_3.cpp:26: error: no matching function for call to `write_list(
std::list<int, std::allocator<int> >&)'
prg6_3.cpp:33: error: no matching function for call to `write_list(
std::list<int, std::allocator<int> >&)'
list1.hpp: In function `void insert_order(std::list<T, std::allocator<_CharT>
>&, const T&) [with T = int]':
prg6_3.cpp:21: instantiated from here
list1.hpp:20: error: `orderd_list' undeclared (first use this function)
list1.hpp:20: error: (Each undeclared identifier is reported only once for each
function it appears in.)
When studying the error messages it seems that the only error list1.hpp generated was:
list1.hpp:20: error: `orderd_list' undeclared (first use this function)
list1.hpp:20: error: (Each undeclared identifier is reported only once for each
function it appears in.)
So:
Code:
orderd_list.insert(curr, item);
Should be:
Code:
ordered_list.insert(curr, item);
You got a handful of warnings though. The other errors seems to be from util.hpp and prg6_3.cpp.
If you are using STL why not use more of it. For instance, STL already contains algorithms for removing non-unique items (in a sorted container).
Heh, sorry! It looks like util.hpp has the same issues (no include for <list> and no "std::" in front of list).
As for the warnings, I'm not too sure why they're being issued, except maybe because you are defining a template; and using the template param as the param into another template (the list).
Oh, don't forget to '#include <iostream>' at the top of util.hpp! It looks like the CPP file is okay (sorry, I didn't have a chance to compile these myself!)
Heh, sorry! It looks like util.hpp has the same issues (no include for <list> and no "std::" in front of list).
As for the warnings, I'm not too sure why they're being issued, except maybe because you are defining a template; and using the template param as the param into another template (the list).
Oh, don't forget to '#include <iostream>' at the top of util.hpp! It looks like the CPP file is okay (sorry, I didn't have a chance to compile these myself!)
Viggy
That's alright. Unfortunately I don't have enough time at the moment to fix all of the errors, so I'll leave it as is and pick it up on Saturday.
Ok. I managed to fix the errors and it compiled (put the using namespace std; before including the header files), but with oodles of fun warnings. The files are attached.
Code:
In file included from prg6_3.cpp:8:
list1.hpp: In function `void insert_order(std::list<T, std::allocator<_CharT>
>&, const T&)':
list1.hpp:8: warning: `std::list<T, std::allocator<_CharT> >::iterator' is
implicitly a typename
list1.hpp:8: warning: implicit typename is deprecated, please see the
documentation for details
list1.hpp:9: warning: `std::list<T, std::allocator<_CharT> >::iterator' is
implicitly a typename
list1.hpp:9: warning: implicit typename is deprecated, please see the
documentation for details
list1.hpp: In function `void remove_duplicates(std::list<T,
std::allocator<_CharT> >&)':
list1.hpp:27: warning: `std::list<T, std::allocator<_CharT> >::iterator' is
implicitly a typename
list1.hpp:27: warning: implicit typename is deprecated, please see the
documentation for details
list1.hpp:28: warning: `std::list<T, std::allocator<_CharT> >::iterator' is
implicitly a typename
list1.hpp:28: warning: implicit typename is deprecated, please see the
documentation for details
In file included from prg6_3.cpp:9:
util.hpp: In function `void write_list(const std::list<T,
std::allocator<_CharT> >&, const std::string&)':
util.hpp:7: warning: `std::list<T, std::allocator<_CharT> >::const_iterator' is
implicitly a typename
util.hpp:7: warning: implicit typename is deprecated, please see the
documentation for details
Simple fix, in list1.hpp, change all the list<T>::iterator or list<T>::const_iterator (in general everywhere you see list<T>::...) to typename list<T>::iterator or typename list<T>::const_iterator (in general, typename list<T>::....).
Also, good luck fixing the program crash when you're debugging
Simple fix, in list1.hpp, change all the list<T>::iterator or list<T>::const_iterator (in general everywhere you see list<T>::...) to typename list<T>::iterator or typename list<T>::const_iterator (in general, typename list<T>::....).
Also, good luck fixing the program crash when you're debugging
Screw it. I'm giving up on this, it's not worth the head ache. The author of my book continuously uses the same util.h and list1.h header files in some of his examples as the book progresses, it's very annoying.
The missing "typename" error is very common. It suddenly appeared on compilers that follow the ANSI C++ spec concerning names within templates.
YourSurrogateGod, the explanation for your latest errors are simple:
Code:
#include <list>
template <typename T>
class foo
{
std::list<T> list_t;
std::list<T>::iterator it; // error, but not on older compilers
};
The problem with the second line is fundamental -- the compiler doesn't know if "iterator" is a type, or a static member variable of std::list<T>, so the compiler throws its hands in the air and gives you an error. This makes sense for the compiler to give you an error, since to specify a static member, you use the "::" (scope resolution operator), therefore the ambiguity.
To tell the compiler that "iterator" is a typename and not a static member of std::list<T>, you use the "typename" qualifier.
Code:
#include <list>
template <typename T>
class foo
{
std::list<T> list_t;
typename std::list<T>::iterator it; // OK
};
You will come across this again, especially if you use Visual C++ 7.x, Dev-C++/MingW, or any ANSI compliant compiler. The problem with the book is that the syntax of leaving out the "typename" worked for many compilers up until recently. So give the book a chance by fixing this problem. I have had to "fix" many header files when compiling under a newer compiler, just for this error alone.
There are a few posts on CodeGuru in this forum and in the Visual C++ forum where persons were getting the very same error you're getting, and couldn't understand why. It is one of the toughest errors to figure out if you are not aware of this issue.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; December 11th, 2004 at 08:09 PM.
The missing "typename" error is very common. It suddenly appeared on compilers that follow the ANSI C++ spec concerning names within templates.
YourSurrogateGod, the explanation for your latest errors are simple:
Code:
#include <list>
template <typename T>
class foo
{
std::list<T> list_t;
std::list<T>::iterator it; // error, but not on older compilers
};
The problem with the second line is fundamental -- the compiler doesn't know if "iterator" is a type, or a static member variable of std::list<T>, so the compiler throws its hands in the air and gives you an error. This makes sense for the compiler to give you an error, since to specify a static member, you use the "::" (scope resolution operator), therefore the ambiguity.
To tell the compiler that "iterator" is a typename and not a static member of std::list<T>, you use the "typename" qualifier.
Code:
#include <list>
template <typename T>
class foo
{
std::list<T> list_t;
typename std::list<T>::iterator it; // OK
};
You will come across this again, especially if you use Visual C++ 7.x, Dev-C++/MingW, or any ANSI compliant compiler. The problem with the book is that the syntax of leaving out the "typename" worked for many compilers up until recently. So give the book a chance by fixing this problem. I have had to "fix" many header files when compiling under a newer compiler, just for this error alone.
There are a few posts on CodeGuru in this forum and in the Visual C++ forum where persons were getting the very same error you're getting, and couldn't understand why. It is one of the toughest errors to figure out if you are not aware of this issue.
Regards,
Paul McKenzie
Hmm... ok.
These are the errors that I'm getting. One thing that I think is odd is the fact that it's giving me a parse error right before template .
Code:
In file included from prg6_3.cpp:8:
list1.hpp: In function `void insert_order(std::list<T, std::allocator<_CharT>
>&, const T&)':
list1.hpp:13: error: parse error before `template'
list1.hpp: In function `void remove_duplicates(std::list<T,
std::allocator<_CharT> >&)':
list1.hpp:32: error: parse error before `template'
In file included from prg6_3.cpp:9:
util.hpp: In function `void write_list(const std::list<T,
std::allocator<_CharT> >&, const std::string&)':
util.hpp:12: error: parse error before `template'
list1.hpp: In function `void insert_order(std::list<T, std::allocator<_CharT>
>&, const T&) [with T = int]':
prg6_3.cpp:21: instantiated from here
list1.hpp:17: error: `curr' undeclared (first use this function)
list1.hpp:17: error: (Each undeclared identifier is reported only once for each
function it appears in.)
list1.hpp:17: error: `end' undeclared (first use this function)
util.hpp: In function `void write_list(const std::list<T,
std::allocator<_CharT> >&, const std::string&) [with T = int]':
prg6_3.cpp:26: instantiated from here
util.hpp:14: error: `iter' undeclared (first use this function)
list1.hpp: In function `void remove_duplicates(std::list<T,
std::allocator<_CharT> >&) [with T = int]':
prg6_3.cpp:29: instantiated from here
list1.hpp:45: error: `p' undeclared (first use this function)
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.