why this code doesn't work!!

From: A. Saksena (abhishek.saksena_at_philips.com)
Date: 02/21/05


Date: Mon, 21 Feb 2005 13:09:32 +0100

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



Relevant Pages

  • Re: question about struct??
    ... a typedef does not create a new type; ... You can then refer to the type simply as "struct st". ... struct var; ...
    (comp.lang.c)
  • Re: check to see if value can be an integer instead of string
    ... > have looked at is int, but what is comming out is a string that may ... The "int" builtin function never returns any value but an integer. ... > var = some var passed to my script ...
    (comp.lang.python)
  • Re: why this code doesnt work!!
    ... Saksena wrote: ... > typedef T var; ... > int main ...
    (comp.lang.cpp)
  • Re: question about struct??
    ... a typedef does not create a new type; ... You can then refer to the type simply as "struct st". ... struct var; ...
    (comp.lang.c)
  • Re: Passing const int * to a function
    ... For var to be constant the declaration of f should be ... int f ... int f (const int *const var) ... Bounce first left and then right and then continue in this same ...
    (comp.lang.c)