Topic: Templates with constant arguments and global functions
Author: "Daniel Parker" <danielp@localhost.com>
Date: 1998/01/19 Raw View
Consider the following:
template <int N_>
class A
{
};
template <int N_>
void f( const A<N_>& x )
{
}
void main()
{
A<3> x;
f( x );
}
Compiling with Visual C++ V 5.0, with Service Pack 3 installed, I get the
following error:
error C2783: 'void __cdecl f(const class A< ?? > &)' : could not deduce
template argument for 'N_'
On the other hand, calling the function specifying the template argument
explicitly works, i.e.,
f<3>( x )
succeeds.
This is a bug in Visual C++, right? Or am I missing something? This is
creating a problem for me because it prevents me from overloading global IO
stream operators for some classes with constant template arguments.
Suggestions?
Regards,
Daniel Parker
Please do not use reply, click danielp@anabasis.com instead.
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: Alexandre Oliva <oliva@dcc.unicamp.br>
Date: 1998/01/20 Raw View
Daniel Parker writes:
> error C2783: 'void __cdecl f(const class A< ?? > &)' : could not deduce
> template argument for 'N_'
> On the other hand, calling the function specifying the template argument
> explicitly works, i.e.,
> f<3>( x )
> This is a bug in Visual C++, right?
Yes, ANSI/ISO C++-compliant compilers must deduce N_ in your template
definition.
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]