template specializiation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I have a question concerning template specialization where gcc behaves different than other compilers. (I already asked this on comp.lang.c++.moderated, but got no response).

Is it possible to specialize just a member variable? (example code below). The C++ standard is a little bit vague on this or perhaps I just didn't get it. Existing C++ compilers seem to be undecided, gcc and Microsoft accept the sample code, while icc, Comeau and Borland reject it.

struct A {
    const A* a;
};

template <const char* c> struct B {
    static const A b;
};

extern const char c[1]="";
extern const char d[1]="";

template<> const A B<c>::b = {&B<d>::b};
template<> const A B<d>::b = {&B<c>::b};


I tend to think it is at least not allowed in this form (two
specialization referencing each other), at least icc gives a somewhat
convincing error message. Does anyone have an idea how to fix it? I want
to use template specialization to plug in information in a template
class, the different specializations need to reference each other. I do
not want to specialize the whole class, as most of it would be redundant.
Also I would like to add new specialization without changing header
files, which _seems_ to work using the approach shown above, but would
not work if I had to specialize the whole class.

Thomas


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux