471,594 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

[BUG]? explicit specialization of templates

I have a query concerning the handling of explicit specializations.
Essentially, I want to know whether it is legal to take a template
like
template<class X> typename X::A Foo(typename X::B, typename X::C)
and specialise it in the case X takes some particular value, such as:
template<> typename Bar::A Foo<Bar>(typename Bar::B, typename Bar::C)


Here is a complete example of what I am trying to do
-------------------------------------------------
template<class linktype> typename linktype::mychildset&
GetCList(typename linktype::parent&,linktype* =0);

struct UniqueID
{
typedef int mychildset;
typedef int parent;
};

int k;

template<> UniqueID::mychildset& GetCList<UniqueID>(UniqueID::parent&
par,UniqueID*)
{
return k;
}

int main()
{
return 0;
}

-------------------------------------------------

..NET 2003 will not compile this code, giving the error message
"explicit specialization; 'UniqueID::mychildset
&GetCList<UniqueID>(UniqueID::parent &,UniqueID *)' is not a
specialization of a function template", whereas the original .NET
accepted it. I was wondering whether this was due to enhanced
standards conformance in '03, or whether it might have some other
cause (e.g. a compiler bug). (BTW, I tried the code on
www.comeaucomputing.com, which accepted it.) Any information
gratefully recieved!

Best,

Thomas Barnet-Lamb
Lionhead Studios Ltd.
www.lionhead.com
Nov 16 '05 #1
1 1438
"Thomas Barnet-Lamb" <tb****@lionhead.com> wrote:
[...]
template<class linktype> typename linktype::mychildset&
GetCList(typename linktype::parent&,linktype* =0);

struct UniqueID
{
typedef int mychildset;
typedef int parent;
};

int k;

template<> UniqueID::mychildset& GetCList<UniqueID>(UniqueID::parent&
par,UniqueID*)
{
return k;
}

int main()
{
return 0;
}
[...]

Comeau is happy with your code:

--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--

Thank you for testing your code with Comeau C/C++!
Tell others about http://www.comeaucomputing.com/tryitout !

Your Comeau C/C++ test results are as follows:

Comeau C/C++ 4.3.1 (Mar 1 2003 20:09:34) for ONLINE_EVALUATION_BETA1
Copyright 1988-2003 Comeau Computing. All rights reserved.
MODE:strict errors C++

In strict mode, with -tused, Compile succeeded (but remember, the Comeau
online compiler does not link).

--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--

Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers org

"My hair style calls into immediate question all my judgements."
Scott Meyers

(http://www.google.de/groups?selm=MPG...ws.hevanet.com)


Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Patrick Kowalzick | last post: by
11 posts views Thread by Gernot Frisch | last post: by
3 posts views Thread by Steven T. Hatton | last post: by
9 posts views Thread by stephen.diverdi | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.