Template specialization error
corey taylor
corey.taylor@gmail.com
Tue May 31 20:42:00 GMT 2005
Mark,
This may help. Section 14.1 paragraph 7
A non-type template-parameter shall not be declared to have floating
point, class, or void type. [Example:
template<double d> class X; // error
template<double* pd> class Y; // OK
template<double& rd> class Z; // OK
—end example]
corey
On 5/30/05, Mark Norman <mpnorman@gmail.com> wrote:
> Hi,
>
> I'm trying to port some code to work on gcc. Unfortunately I have
> come across an error which I have been unable to solve. I have
> created a small example program which illustrates the compiler error I
> get.
>
> Compiling the following code using gcc 3.3.4 or 3.4.3 gives the following error:
> test.C: In instantiation of `Bar<void>':
> test.C:31: instantiated from here
> test.C:7: error: forming reference to void
>
> When calling "fun<void>( k )" it appears that g++ gets confused with
> the last argument in template 3 (see code) even though it should be
> using the void specialization in Template 2.
>
>
>
> template<class T>
> struct Foo;
>
> template<class T>
> struct Bar
> {
> typedef Foo< const T& > fooTypedef;
> };
>
> // Template 1
> template <class T>
> T fun( int Key )
> { };
>
> // Template 2
> // Specialization of fun template for void.
> template <> inline
> void fun<void>( int Key ) { };
>
> // Template 3
> // The following function causes the error. If you remove/rename this function
> // or replace "typename Bar<T>::fooTypedef" with "Foo< const T& >"
> // it compiles ok.
> template <class T>
> T fun( int Key, const typename Bar<T>::fooTypedef& theFoo )
> { };
>
>
> int main()
> {
> int k;
>
> fun<char>( k );
> fun<void>( k );
> }
>
>
> Am I doing something incorrectly here?
>
> Thanks for any help you can provide.
>
> Mark
>
More information about the Gcc-help
mailing list