Errors: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
Kheun
December 8th, 2004, 02:23 AM
Do you have this line?
using std::list;
Gabriel Fleseriu
December 8th, 2004, 02:41 AM
Do you have this line?
using std::list;
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.
Who is 'stop' ? You mean 'end', don't you? ;)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: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> >&)'
MrViggy
December 8th, 2004, 03:56 PM
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
YourSurrogateGod
December 8th, 2004, 10:27 PM
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".
ViggyYes, 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.#include <list>
template <typename T>
void insert_order(std::list<T> & ordered_list, const T & item)
{
std::list<T>::iterator curr = ordered_list.begin();
std::list<T>::iterator end = ordered_list.end();
curr++;
}
}
}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.)
marten_range
December 9th, 2004, 03:00 AM
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:
orderd_list.insert(curr, item);
Should be:
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).
// ListTest.cpp : Defines the entry point for the console application.
//
find_predicate is a predicate used to locate the insertion point. std::find_if terminates when the predicate returns true.
Hope this is of some help.
MrViggy
December 9th, 2004, 10:18 AM
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
YourSurrogateGod
December 9th, 2004, 06:17 PM
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!)
ViggyThat'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.
YourSurrogateGod
December 10th, 2004, 11:50 PM
When studying the error messages it seems that the only error list1.hpp generated was:
So:
orderd_list.insert(curr, item);
Should be:
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).
// ListTest.cpp : Defines the entry point for the console application.
//
find_predicate is a predicate used to locate the insertion point. std::find_if terminates when the predicate returns true.
Hope this is of some help.Thanks for your help. This is an exercise that I picked up from a book, so that I can improve my skills.
YourSurrogateGod
December 11th, 2004, 12:28 PM
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.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
cma
December 11th, 2004, 12:40 PM
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 :rolleyes:
YourSurrogateGod
December 11th, 2004, 06:51 PM
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 :rolleyes: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.
Paul McKenzie
December 11th, 2004, 07:07 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:
#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.
#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
YourSurrogateGod
December 11th, 2004, 07:28 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:
#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.
#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 McKenzieHmm... 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 :confused: .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)Here is the list1.h file.#include <iostream>
#include <list>
for(iter = alist.begin(); iter != alist.end(); iter++)
{
std::cout << * iter << separator;
}
std::cout << "\n\n";
}
wien
December 11th, 2004, 07:48 PM
That's typename not template. ;)
YourSurrogateGod
December 11th, 2004, 07:57 PM
That's typename not template. ;)Hooray, I'm retarted today :rolleyes: .
On the bright side it compiled, but I got a segmentation fault right after I printed out the (before the duplicates were removed.)
HighCommander4
December 11th, 2004, 08:02 PM
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.
I've come across this issue before, though it did not take me much effort to resolve it... my compiler, Dev-Cpp 4.9.9.0, actually pointer out what the error was and instructed, in the error message, to add typename.
wien
December 11th, 2004, 08:50 PM
On the bright side it compiled, but I got a segmentation fault right after I printed out the (before the duplicates were removed.)Actually, it's while the duplicates are being removed. You're incrementing curr inside the second while-loop. That way you go out of bounds in a hurry.
Actually, it's while the duplicates are being removed. You're incrementing curr inside the second while-loop. That way you go out of bounds in a hurry.