   Partial specialisation of nested template class
  Very briefly, here is the code obviously pertinent to my problem: // Image class for image manipulation.// This seems to compile just fine; nothing strange about it.template<unsigned int CHAN, class data_t=float>class image{public:class pixel;   // ...};// No problems here, either. This is a general pixel class// for images with n colour channels.template <unsigned CHAN, class data_t>class image<CHAN, data_t>::pixel{   // ...};// Now I want to specialise the pixel for single-channel// images to cut down on looping over the colour channels// (this should give my compiler some nice opportunities for// optimisation, and some of this stuff is SLOW).//   However, the compiler barfs on the following ...template <class data_t>class image<(unsigned) 1, data_t>::pixel{   // ...};If the first pixel class is a valid class, what's wrong with the partial specialisation?g++ spits the following at me (pointing at the line where the partially specialised class is declared):invalid definition of qualified type `image<(unsigned int)(1), data_t>:: pixel'`struct image<(unsigned int)(1), data_t>::<anonymous>' does not declare a template type   Edit: Damned smileys.[edited by - Miserable on February 4, 2004 1:27:04 AM]
  ok i know this has got nothing to do with your post...and for that im sorry...but how do you get your program code in a post like you have there... so it looks like it does in compilers...im just using// start code// end code in my posts which looks awfull....anyway yeah sorry that it has no relevence but it caught my eye and its 6am and i should go to bed...lol ;quote:Original post by Grofit  ok i know this has got nothing to do with your post...and for that im sorry...but how do you get your program code in a post like you have there... so it looks like it does in compilers...im just using// start code// end code in my posts which looks awfull....anyway yeah sorry that it has no relevence but it caught my eye and its 6am and i should go to bed...lol   [ source ] ... [ /source ] (without the spaces, of course); it''s in the FAQ. ;  I''m not sure it''s legal C++ to do a partial template specialization of a nested non-template class of a template class without doing a partial specialization of the entire enclosing template class. ;  You might consider something akin to how the standard library does iterator_traits, having pixel be a non-nested template class parameterized on the template arguments to image.   "Sneftel is correct, if rather vulgar." --Flarelocke ;quote:Original post by SiCrane   I'm not sure it's legal C++ to do a partial template specialization of a nested non-template class of a template class without doing a partial specialization of the entire enclosing template class.   Maybe that's it; that would certainly explain why I'm getting weird errors, and I can work around it (e.g. template the image class on pixel classes, one of which is specialised; the useful image types are typedefs, anyway, so this wouldn't really change very much). Nevertheless, I fail to see why   this would be illegal even if it is (the intent is obvious, and the syntax seems to allow for it), and without intending any offence to you, I wonder if anyone can provide a definitive   answer on this one?quote:Original post by Sneftel   You might consider something akin to how the standard library does iterator_traits, having pixel be a non-nested template class parameterized on the template arguments to image.... Or that, perhaps more elegant. At least working around the problem should not be difficult ...   [edited by - Miserable on February 4, 2004 2:02:58 AM];  From section 14.5.4.3 of the C++ Standard (w/ TC1): "The template parameter list of a member of a class template partial specialization shall match the template parameter list of the class template partial specialization."So what you''re doing is declaring a member of class template partial specialization without declaring the partial template specialization of the enclosing class; therefore by default the partial template specialization of the member of the class template partial specialization will not match the template parameter list of the class template partial specialization, because there is no such partial specialization.Futhermore it goes on to state: "The members of the class template partial specialization are unrelated to the members of the primary template." Which basically means, that even if you were able to declare the template partial specialization of a member type, it wouldn''t have any impact on the primary template class, because it''s members are considered completely distinct from the types declared as partial specializations of the class.;template<typename T1, typename T2>class B;template<typename T1, typename T2>class A{public:    typedef B<T1, T2> B;};template<typename T1, typename T2>class B{};template<typename T2>class B<int, T2>{};int main(){    A<int, int>::B b1;    A<bool, int>::B b2;} "Sneftel is correct, if rather vulgar." --Flarelocke ;quote:Original post by SiCrane  From section 14.5.4.3 of the C++ Standard (w/ TC1): "The template parameter list of a member of a class template partial specialization shall match the template parameter list of the class template partial specialization."So what you''re doing is declaring a member of class template partial specialization without declaring the partial template specialization of the enclosing class; therefore by default the partial template specialization of the member of the class template partial specialization will not match the template parameter list of the class template partial specialization, because there is no such partial specialization.Futhermore it goes on to state: "The members of the class template partial specialization are unrelated to the members of the primary template." Which basically means, that even if you were able to declare the template partial specialization of a member type, it wouldn''t have any impact on the primary template class, because it''s members are considered completely distinct from the types declared as partial specializations of the class. Aha! Thank you very much; that is an amply definitive answer. I really should get a copy of the Standard, one of these days ... ;  Well, if you plan on it, there''s never been a better time. BSI finally got permission from ISO to print the Standard w/ TC1 as a book. Now you can snag a hardcopy for only $65 (US). This is much better compared to the couple hundred that it cost before. Or the $281 that ANSI is currently selling the PDF version for. 