Topic: Template constants deduction
Author: "Philippe A. Bouchard" <philippeb@videotron.ca>
Date: 22 Jun 2002 00:35:40 GMT Raw View
Is this a bug or I am forgetting something? The following program:
#include <iostream>
using namespace std;
struct Type
{
int i;
};
template <typename _T, int _T::*>
struct Number
{
};
template <typename _T, int _T::*>
void foo(Number<_T, int _T::*> const &)
{
cout << __PRETTY_FUNCTION__ << endl;
}
int main()
{
foo(Number<Type, & Type::i>());
return 0;
}
Returns:
template.cpp:18: type/value mismatch at argument 2 in template parameter
list
for `template<_T, int _T::*<anonymous> > struct Number'
template.cpp:18: expected a constant of type `int _T::*', got `int _T::*'
template.cpp:19: ISO C++ forbids declaration of `parameter' with no type
template.cpp: In function `int main()':
template.cpp:27: no matching function for call to `foo(Number<Type,
&Type::i>)'
Under:
gcc version 3.0.4
Regards,
Philippe A. Bouchard
Software Engineer
Fornux
www.fornux.com
Email: support@fornux.com
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: "Giovanni Bajo" <giovannibajo@REMOVEliberoTHIS.it>
Date: Sun, 23 Jun 2002 05:20:30 GMT Raw View
"Philippe A. Bouchard" <philippeb@videotron.ca> ha scritto nel messaggio
news:DDHQ8.14873$x82.422726@weber.videotron.net...
> template <typename _T, int _T::*>
> void foo(Number<_T, int _T::*> const &)
You're not defining a name for the second template parameter. The correct
code is:
template <typename _T, int _T::*_V>
void foo(Number<_T, _V> const &)
which compiles and works under Comeau.
Giovanni Bajo
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: "Philippe A. Bouchard" <philippeb@videotron.ca>
Date: Tue, 25 Jun 2002 17:28:47 GMT Raw View
Is this a bug or I am forgetting something? The following program:
#include <iostream>
using namespace std;
struct Type
{
int i;
};
template <typename _T, int _T::*>
struct Number
{
};
template <typename _T, int _T::*>
void foo(Number<_T, int _T::*> const &)
{
cout << __PRETTY_FUNCTION__ << endl;
}
int main()
{
foo(Number<Type, & Type::i>());
return 0;
}
Returns:
template.cpp:18: type/value mismatch at argument 2 in template parameter
list
for `template<_T, int _T::*<anonymous> > struct Number'
template.cpp:18: expected a constant of type `int _T::*', got `int _T::*'
template.cpp:19: ISO C++ forbids declaration of `parameter' with no type
template.cpp: In function `int main()':
template.cpp:27: no matching function for call to `foo(Number<Type,
&Type::i>)'
Under:
gcc version 3.0.4
Regards,
Philippe A. Bouchard
Software Engineer
Fornux
www.fornux.com
Email: support@fornux.com
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]