static member initialization

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kiryazev@gmail.com

    #1

    static member initialization

    Hello! The following code compiles fine.

    template <typename C>
    struct T
    {
    typedef typename C::Type * pType;
    template <pType A>
    struct D
    {
    static const pType Val;
    };
    };

    template<typena me C>
    template<typena me C::Type* A// line #13
    const typename T<C>::pType T<C>::D<A>::Va l = A;

    int main()
    {
    }

    But if one replaces line#13 with

    template<typena me T<C>::pType A>

    it does not.
    Does anybody know why?

  • Victor Bazarov

    #2
    Re: static member initialization

    kiryazev@gmail. com wrote:
    Hello! The following code compiles fine.
    >
    template <typename C>
    struct T
    {
    typedef typename C::Type * pType;
    template <pType A>
    struct D
    {
    static const pType Val;
    };
    };
    >
    template<typena me C>
    template<typena me C::Type* A// line #13
    const typename T<C>::pType T<C>::D<A>::Va l = A;
    >
    int main()
    {
    }
    >
    But if one replaces line#13 with
    >
    template<typena me T<C>::pType A>
    >
    it does not.
    Does anybody know why?
    I can tell you the Comeau online trial compiler says it's
    because "declaratio n is incompatible with constant
    "C::Type *A" (declared at line 5)"

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask


    Comment

    • kiryazev@gmail.com

      #3
      Re: static member initialization

      Victor Bazarov wrote:
      I can tell you the Comeau online trial compiler says it's
      because "declaratio n is incompatible with constant
      "C::Type *A" (declared at line 5)"
      Thanks. But I don't see the difference between these two variants.
      (typeid(typenam e T<C>::pType) == typeid(typename C::Type*)) returns
      true. Moreover struct D parametrized using pType not C::Type*.

      Comment

      • Victor Bazarov

        #4
        Re: static member initialization

        kiryazev@gmail. com wrote:
        Victor Bazarov wrote:
        >
        >I can tell you the Comeau online trial compiler says it's
        >because "declaratio n is incompatible with constant
        > "C::Type *A" (declared at line 5)"
        >
        Thanks. But I don't see the difference between these two variants.
        (typeid(typenam e T<C>::pType) == typeid(typename C::Type*)) returns
        true. Moreover struct D parametrized using pType not C::Type*.
        I was curious about that as well. I don't have the exact answer, for
        you though. My best guess is that by the time you try using the
        'T<C>::pType' the T<Chasn't been instantitated yet. It would cause
        an instantiation but does not until you actually instantiate the 'Val'
        member in 'D', and then the compiler probably gets lost trying to
        resolve what 'pType' is supposed to be. The difference with the 'Val'
        declaration itself is that here you're trying to use it as a template
        argument.

        V
        --
        Please remove capital 'A's when replying by e-mail
        I do not respond to top-posted replies, please don't ask


        Comment

        Working...