CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 22

Threaded View

  1. #18
    Join Date
    May 2007
    Location
    Scotland
    Posts
    1,164

    Re: Accessibility of virtual functions

    Quote Originally Posted by JohnW@Wessex View Post
    Does anyone know if there are there technical reasons for these prohibitions or are they just arbitrary?
    I'm not sure of the technical reasons as to why it is the case, but the standard (or, at least the 2005 draft that I have) in section 14.7.18 says:

    In an explicit specialization declaration for a member of a class template or a member template that appears in namespace
    scope, the member template and some of its enclosing class templates may remain unspecialized, except that the declaration
    shall not explicitly specialize a class member template if its enclosing class templates are not explicitly specialized
    as well. In such explicit specialization declaration, the keyword template followed by a template-parameter-list shall
    be provided instead of the template<> preceding the explicit specialization declaration of the member. The types of
    the template-parameters in the template-parameter-list shall be the same as those specified in the primary template
    definition. [ Example:

    Code:
    template < class T1 > class A {
      template < class T2 > class B {
        template < class T3 > void mf1(T3 );
        void mf2 ();
      };
    };
    template <> template < class X>
    class A<int >::B {
      template < class T > void mf1(T);
    };
    template <> template <> template < class T>
    void A<int >::B<double >:: mf1(T t ) { }
    template < class Y > template <>
    void A<Y >::B<double >:: mf2 () { } / / ill-formed; B<double> is specialized but
                                        / / its enclosing class template A is not
    I did once hear that the reason why the behaviour was prevented, was because it is technically difficult for the compilers to allow such behaviour, and therefore the standard disallowed it. But that explanation seems a little odd to me and I don't trust it. If anyone can give a good technical explanation as to why the behaviour was prevented, then I'd be happy to hear it.

    Incidently, although there have been rumours that C++0x will make the above legal, it doesn't look like this will be the case as the Oct 2008 version of the C++0x draft keeps the above quotation unchanged. Therefore, VS allows you to get away with ill-formed code, which is a bit annoying.
    Last edited by PredicateNormative; January 23rd, 2009 at 06:37 AM. Reason: Made 'template < class Y > template <>' bold

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured