🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: grads
Article #7

Re: Why doesn't this simple program compile?

#7
From: Enno Sandner
Date: Fri, 01 Sep 1995 07:54
54 lines
1995 bytes
The program is correct according to the draft-standard.
But most compilers, including g++ doesn't support this
new style of template-argument matching, therefore you 
are still restricted to a more or less exact-type matching.
So you'll have to use cast's to fix your problem.

	regards
		Enno


chou@cs.ucla.edu (Ching-Tsun Chou) writes:
>I'm reading S.B. Lippman's book "C++ Primer" (2nd ed.) and trying out
>the example programs in it using gcc-2.7.0.  According to Lippman's book,
>the following simple program should compile, though when executed it should
>fail at the line marked by "// ERROR".  But I couldn't even compile it
>using gcc-2.7.0.  If the program is in a file "prog.cc", then compiling it
>with "g++ prog.cc" generates the following error message:
>
>  prog.cc: In function `int main()':
>  prog.cc:50: type unification failed for function template
>  `template <class Type> void swap(Array<...> &, int, int)'
>
>
>template <class Type>
>class Array
>{
> ...
>};
>
>template <class Type>
>class ArrayRC : public Array<Type>
>{
> ...
>};
>
>template <class Type>
>void swap( Array<Type> &A, int i, int j )
>{
> ...
>}
>
>main()
>{
>  Array<int> ia1;
>  ArrayRC<int> ia2;
>  
>  cout << "swap with Array ia1" << endl ;
>  swap( ia1, 1, ia1.getSize() );
>  
>  cout << "swap with ArrayRC ia2" << endl ;
>  swap( ia2, 1, ia2.getSize() );    // ERROR
>  
>  return 0;
>}
Technical Details
Message-ID: <ENNO.95Sep1095421@kitz.inferenzsysteme.informatik.th-darmstadt.de>
Path: arc1-ca.pugleaf.net!news.th-darmstadt.de!news!enno
References: <425hh1$joo@delphi.cs.ucla.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.th-darmstadt.de!news!enno
From: enno@inferenzsysteme.informatik.th-darmstadt.de (Enno Sandner)
Newsgroups: grads,gnu.g++.help,comp.lang.c++
Subject: Re: Why doesn't this simple program compile?
Date: 01 Sep 1995 07:54:21 GMT
Organization: Fachbereich Informatik, TH Darmstadt
Message-ID: <ENNO.95Sep1095421@kitz.inferenzsysteme.informatik.th-darmstadt.de>
References: <425hh1$joo@delphi.cs.ucla.edu>
NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
In-reply-to: chou@cs.ucla.edu's message of 31 Aug 1995 23:44:33 GMT