* Template specialization error
@ 2005-05-30 15:29 Mark Norman
2005-05-31 20:42 ` corey taylor
0 siblings, 1 reply; 2+ messages in thread
From: Mark Norman @ 2005-05-30 15:29 UTC (permalink / raw)
To: gcc-help
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Template specialization error
2005-05-30 15:29 Template specialization error Mark Norman
@ 2005-05-31 20:42 ` corey taylor
0 siblings, 0 replies; 2+ messages in thread
From: corey taylor @ 2005-05-31 20:42 UTC (permalink / raw)
To: Mark Norman; +Cc: gcc-help
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
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-05-31 20:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-30 15:29 Template specialization error Mark Norman
2005-05-31 20:42 ` corey taylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).