Re: type mismatch when compile 1999 code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2011-06-23 at 08:56 +0200, Axel Freyn wrote:
> Hi Eric,
> 
> On Wed, Jun 22, 2011 at 11:05:33PM -0700, eric wrote:
> > Dear gcc programers:
> > 
> >   I tried to copy (from internet download book's example source code,
> > from
> > http://comscigate.com/BookCode/cppbooks.htm
> > on C++ Primer 3rd Ed, written by Lippman , Lajoie
> > that source code is written before 1999 and I guess is compiled based on
> > borland's compiler
> > I tried to compile/run chap17,  text_query.C
> > attach 4 related files(I already modify a little bit, ie replace
> > iostream.h by iostream and add using namespace std;)
> > ------------------
> > eric@eric-laptop:~/CppPrimer3/download/chap17$ g++ Query.C text_query.C
> > In file included from Query.C:1:0:
> > Query.h:27:41: error: type/value mismatch at argument 3 in template
> > parameter list for ‘template<class _Key, class _Compare, class _Alloc>
> > class std::set’
> > Query.h:27:41: error:   expected a type, got ‘allocator’
> > Query.h:28:36: error: type/value mismatch at argument 2 in template
> > parameter list for ‘template<class _Tp, class _Alloc> class std::vector’
> > Query.h:28:36: error:   expected a type, got ‘allocator’
> > ----------
> > this is just first 4 errors of the whole(a lot).
> > /* which I believe is gcc specific(4.5.2), so I decide not post to
> > comp.lang.c++ */
> No, it's a problem in your code. GCC is absolutely right.
> 
> GCC states that in Query.h line 27 you're using "allocator" as a template
> parameter. At this position, you would need a type, but "allocator" is
> no type (but nevertheless: allocator is some object/word known to the
> compiler).
> 
> The first line in question is the following:
> > 	const set< short,less<short>,allocator >    *solution();
> Due to your "using namespace std;" the word allocator is resolved to the
> standard template "std::allocator" defined in <memory>.
> However, std::allocator is a TEMPLATE, so you have to pass the type of
> variable which you want to allocate: 
> > 	const set< short,less<short>,allocator<short> >    *solution();
> allocator<short> IS a type, so gcc will be happy :-)
> 
> (and of course you need equivalent changes throughout your code).
> 
> On the other hand: if you don't pass a third parameter to std::set, it
> will use by default std::allocator<T> (with T being the appropriate
> type). The same is true for the second template parameter: std::set
> defaults to use std::less<T> for comparisons.
> So, you can just replace this line by
> > 	const set< short >    *solution();
> which will give you the same behaviour.
> 
> 
> HTH,
> 
> Axel
---------------
I tried to add <short> after allocator to become allocator<short>
improve
but still not compile
this is result I get
------------
eric@eric-laptop:~/CppPrimer3/download/chap17$ g++ Query.C UserQuery.C
TextQuery.C text_query.C  
In file included from UserQuery.C:1:0:
UserQuery.h:46:68: error: wrong number of template arguments (3, should
be 2)
/usr/local/lib/gcc/i686-pc-linux-gnu/4.5.2/../../../../include/c
++/4.5.2/bits/stl_stack.h:92:11: error: provided for ‘template<class
_Tp, class _Sequence> class std::stack’
UserQuery.h:47:68: error: wrong number of template arguments (3, should
be 2)
/usr/local/lib/gcc/i686-pc-linux-gnu/4.5.2/../../../../include/c
++/4.5.2/bits/stl_stack.h:92:11: error: provided for ‘template<class
_Tp, class _Sequence> class std::stack’
UserQuery.h: In member function ‘void UserQuery::evalAnd()’:
UserQuery.h:73:28: error: request for member ‘top’ in
‘((UserQuery*)this)->UserQuery::_query_stack’, which is of non-class
type ‘int’
UserQuery.h:73:48: error: request for member ‘pop’ in
‘((UserQuery*)this)->UserQuery::_query_stack’, which is of non-class
type ‘int’
UserQuery.h:79:14: error: request for member ‘push’ in
‘((UserQuery*)this)->UserQuery::_current_op’, which is of non-class type
‘int’
UserQuery.h: In member function ‘void UserQuery::evalOr()’:
UserQuery.h:88:28: error: request for member ‘top’ in
‘((UserQuery*)this)->UserQuery::_query_stack’, which is of non-class
type ‘int’
UserQuery.h:88:48: error: request for member ‘pop’ in
‘((UserQuery*)this)->UserQuery::_query_stack’, which is of non-class
type ‘int’
UserQuery.h:94:14: error: request for member ‘push’ in
‘((UserQuery*)this)->UserQuery::_current_op’, which is of non-class type
‘int’
UserQuery.h: In member function ‘void UserQuery::evalNot()’:
-------------------------------------------------
this is only first couple lines of errors, it still have a lot
is stack(template) is we defined or system(compiler) defined? why it
must need 2 in stead of 3?  so should I eliminate last parameter?
and 
how about other error?  
need any advancer's help and thanks a lot in advance, Eric




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux