Re: why this code doesn't work!!

From: Thomas Maier-Komor (maierkom_at_lpr.e-technik.tu-muenchen.de)
Date: 02/22/05


Date: Tue, 22 Feb 2005 13:03:44 +0100


  A. Saksena wrote:
> Hi all,
> Why this code does't work!!
> ========================
> #include <iostream>
> template<typename T>
> class a
> {
> public:
> typedef T var;
> };
>
> class b
> {
> };
>
> template<typename T>
> void connect(typename a<T>::var& v1,typename a<T>::var& v2){}
>
> int main()
> {
> a<b>::var v1,v2;
> connect(v1,v2);
>
> }
> =======================
>
> During compilation with gcc(3.2.3) I get following error:-
> $ g++ problem.cpp
> problem.cpp: In function `int main()':
> problem.cpp:19: no matching function for call to `connect(b&, b&)'
>
> I would expect to template function connect(b&, b&) to exist.
>
> If this is not legal c++. Is there is way way to implement suct a
> functionality?
>
>
> Abhishek
>

I think the correct template parameter cannot be deduced.
If you supply it explicitly it works (g++ and Sun's CC)

i.e.:
connect<b>(v1,v2);

Tom

-- 
________________________________________________________________________
Dipl.-Ing. Thomas Maier-Komor                   http://www.rcs.ei.tum.de
Institute for Real-Time Computer Systems (RCS)      fon +49-89-289-23578
Technische Universitaet Muenchen, D-80290 Muenchen  fax +49-89-289-23555


Relevant Pages