How can I solve below template partial specialization problems?

I want to specialize template when return type is void.

==========================================

template <char const*& T, class U, class X>
class CSpecialize
{
public:
CSpecialize(X (U::*pfunc)())
: m_pFunc(pfunc)
{
}

X (U::*m_pFunc)();
};

template <char const*&T, class U>
class CSpecialize<T, U, void>
{
public:
CSpecialize(void (U::*pfunc)())
: m_pFunc(pfunc)
{
}
private:
void (U::*m_pFunc)();
};

compiler error message is

error C2755: 'CSpecialize<T,U,void>' : non-type parameter of a partial specialization must be a simple identifier



Answer this question

How can I solve below template partial specialization problems?

  • VoxB

    We don't have an exact date yet - but I can say that it won't be in 2006.

  • Jey23

    thank you for your attention.

    however, If I follow your answer, I must change program design. T.T

    unfortunately, It's a greate job to me.


  • p3ga5u5

    I can confirm that this is a bug in Visual C++ 2005. The problem is in the code that checks that the usage of a non-type template parameter in a partial specialization is correct (specifically checking 14.5.4/9). The use of the '*&' as part of the type of the non-type template parameter confuses the compiler. I have a fix for the issue.

  • JED_

    its great that MS admits bugs. i really love that.

    i do wish we could get more frequent service packs. we (out here) are making our living dependent on the compiler. is there a rough time frame for ORCAS

    BTW ..... great great product (VS2005)

    thanks


  • Dianna117030

    And is that fix available Or will it be included in a future service pack

  • Dhaval-Patel

    I thought so. But since you can't compile it in VS 2005, you should consider alternative ways.

  • shan_itc

    Comeau can also compile it.

    Perhaps you can do this (which at least compiles):

    template <char const*& T, class U, class X>

    class CSpecialize

    {

    public:

    CSpecialize(X (U::*pfunc)())

    : m_pFunc(pfunc)

    {

    }

    X (U::*m_pFunc)();

    };

    template <char const*&T, class U>

    class CSpecializeDerive : CSpecialize<T, U, void>

    {

    public:

    CSpecializeDerive(void (U::*pfunc)()):

    CSpecialize(((void)(U::*m_pFunc))pfunc)

    {

    }

    private:

    void (U::*m_pFunc)();

    };



  • Daan Banaan

    a workaround for this problem is:

    template <const char *& Reference>
    class StringReference
    {
    public:
    static const char* ref()
    {
    return Reference;
    }
    };

    template <typename T, class U, class X>

    class CSpecialize

    {

    ......

    };

    now instantiate CSpecialize the following way:

    //global

    const char *t;

    // local

    CSpecialize<StringReference<t, class_u, class_x> mySpecialisation;




  • Boulderdude

    It is not currently available (it only exists on one enlistment on my machine). The fix will probably first see the light of day as part of the Orcas release.

  • BrianM

    vs 2005 cann't compile it but gcc 4.0 can do it !!!

    Can anyone help me


  • How can I solve below template partial specialization problems?