template export question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • New_user

    template export question

    Hello.

    Excerpt from ISO/IEC 14882 :
    14/6
    A namespace-scope declaration or definition of ........skipped ...... a non-
    inline member function of a class template or a static data member of a class
    template may be preceded by the export keyword.

    and from http://www.comeaucomputing.com/4.3.0...5+/43stuff.txt :
    A template must be declared export at both the point of definition and
    the point of reference.

    I have some files:

    //templ.h
    template<class T>
    class A
    {
    public:
    void fun();
    static int i_;
    };
    //I want to export A<T>::fun and A<T>::i_, but I do not want to declare class
    //A as exported

    //def.cpp
    //1!
    //exported definitions are here, ordering problems?
    //fun first declared as non-exported and later as exported?

    export template<class T>
    void A<T>::fun()
    {
    }

    export template<class T>
    int A<T>::i_ = 0;

    //user.cpp
    //2! here's class usage

    #include "templ.h"

    int main()
    {
    A<int>a;
    a.fun();
    }

    How can I declare A<T>::fun in user.cpp as exported at the point of reference?
  • Sumit Rajan

    #2
    Re: template export question


    "New_user" <tpochep@mail.r u> wrote in message
    news:d29bee5d.0 404070312.e8ad6 39@posting.goog le.com...[color=blue]
    > Hello.
    >
    > Excerpt from ISO/IEC 14882 :
    > 14/6
    > A namespace-scope declaration or definition of ........skipped ...... a[/color]
    non-[color=blue]
    > inline member function of a class template or a static data member of a[/color]
    class[color=blue]
    > template may be preceded by the export keyword.
    >
    > and from http://www.comeaucomputing.com/4.3.0...5+/43stuff.txt :
    > A template must be declared export at both the point of definition and
    > the point of reference.
    >
    > I have some files:
    >
    > //templ.h
    > template<class T>
    > class A
    > {
    > public:
    > void fun();
    > static int i_;
    > };
    > //I want to export A<T>::fun and A<T>::i_, but I do not want to declare[/color]
    class[color=blue]
    > //A as exported[/color]

    The effect would be exactly the same if you do this:

    //templ.h
    export template <class T>
    class A {
    public:
    void fun();
    static int i_;
    };


    "export" in def.cpp is then redundant.

    //def.cpp

    #include "templ.h"

    template<class T>
    void A<T>::fun()
    {}

    template<class T>
    int A<T>::i_ = 0;



    Regards,
    Sumit.

    [color=blue]
    > //def.cpp
    > //1!
    > //exported definitions are here, ordering problems?
    > //fun first declared as non-exported and later as exported?
    >
    > export template<class T>
    > void A<T>::fun()
    > {
    > }
    >
    > export template<class T>
    > int A<T>::i_ = 0;
    >
    > //user.cpp
    > //2! here's class usage
    >
    > #include "templ.h"
    >
    > int main()
    > {
    > A<int>a;
    > a.fun();
    > }
    >
    > How can I declare A<T>::fun in user.cpp as exported at the point of[/color]
    reference?


    Comment

    • Sumit Rajan

      #3
      Re: template export question


      "New_user" <tpochep@mail.r u> wrote in message
      news:d29bee5d.0 404070312.e8ad6 39@posting.goog le.com...[color=blue]
      > Hello.
      >
      > Excerpt from ISO/IEC 14882 :
      > 14/6
      > A namespace-scope declaration or definition of ........skipped ...... a[/color]
      non-[color=blue]
      > inline member function of a class template or a static data member of a[/color]
      class[color=blue]
      > template may be preceded by the export keyword.
      >
      > and from http://www.comeaucomputing.com/4.3.0...5+/43stuff.txt :
      > A template must be declared export at both the point of definition and
      > the point of reference.
      >
      > I have some files:
      >
      > //templ.h
      > template<class T>
      > class A
      > {
      > public:
      > void fun();
      > static int i_;
      > };
      > //I want to export A<T>::fun and A<T>::i_, but I do not want to declare[/color]
      class[color=blue]
      > //A as exported[/color]

      The effect would be exactly the same if you do this:

      //templ.h
      export template <class T>
      class A {
      public:
      void fun();
      static int i_;
      };


      "export" in def.cpp is then redundant.

      //def.cpp

      #include "templ.h"

      template<class T>
      void A<T>::fun()
      {}

      template<class T>
      int A<T>::i_ = 0;



      Regards,
      Sumit.

      [color=blue]
      > //def.cpp
      > //1!
      > //exported definitions are here, ordering problems?
      > //fun first declared as non-exported and later as exported?
      >
      > export template<class T>
      > void A<T>::fun()
      > {
      > }
      >
      > export template<class T>
      > int A<T>::i_ = 0;
      >
      > //user.cpp
      > //2! here's class usage
      >
      > #include "templ.h"
      >
      > int main()
      > {
      > A<int>a;
      > a.fun();
      > }
      >
      > How can I declare A<T>::fun in user.cpp as exported at the point of[/color]
      reference?


      Comment

      • Sumit Rajan

        #4
        Re: template export question


        "Sumit Rajan" <sumitrajan@myr ealbox.com> wrote in message
        news:c511ro$2mc 9ee$1@ID-206022.news.uni-berlin.de...[color=blue]
        >
        > "New_user" <tpochep@mail.r u> wrote in message
        > news:d29bee5d.0 404070312.e8ad6 39@posting.goog le.com...[/color]
        [color=blue][color=green][color=darkred]
        > > > How can I declare A<T>::fun in user.cpp as exported at the point of[/color][/color]
        > reference?
        >[/color]


        Sorry. Please disregard that post. I missed that question when I read
        through your message. :-)


        Comment

        • Sumit Rajan

          #5
          Re: template export question


          "Sumit Rajan" <sumitrajan@myr ealbox.com> wrote in message
          news:c511ro$2mc 9ee$1@ID-206022.news.uni-berlin.de...[color=blue]
          >
          > "New_user" <tpochep@mail.r u> wrote in message
          > news:d29bee5d.0 404070312.e8ad6 39@posting.goog le.com...[/color]
          [color=blue][color=green][color=darkred]
          > > > How can I declare A<T>::fun in user.cpp as exported at the point of[/color][/color]
          > reference?
          >[/color]


          Sorry. Please disregard that post. I missed that question when I read
          through your message. :-)


          Comment

          • Sumit Rajan

            #6
            Re: template export question


            "Sumit Rajan" <sumitrajan@myr ealbox.com> wrote in message
            news:c511ro$2mc 9ee$1@ID-206022.news.uni-berlin.de...[color=blue]
            >
            > "New_user" <tpochep@mail.r u> wrote in message
            > news:d29bee5d.0 404070312.e8ad6 39@posting.goog le.com...[/color]
            [color=blue][color=green][color=darkred]
            > > > How can I declare A<T>::fun in user.cpp as exported at the point of[/color][/color]
            > reference?
            >[/color]


            Sorry. Please disregard that post. I missed that question when I read
            through your message. :-)



            Comment

            • Sumit Rajan

              #7
              Re: template export question


              "Sumit Rajan" <sumitrajan@myr ealbox.com> wrote in message
              news:c511ro$2mc 9ee$1@ID-206022.news.uni-berlin.de...[color=blue]
              >
              > "New_user" <tpochep@mail.r u> wrote in message
              > news:d29bee5d.0 404070312.e8ad6 39@posting.goog le.com...[/color]
              [color=blue][color=green][color=darkred]
              > > > How can I declare A<T>::fun in user.cpp as exported at the point of[/color][/color]
              > reference?
              >[/color]


              Sorry. Please disregard that post. I missed that question when I read
              through your message. :-)



              Comment

              • Denis Remezov

                #8
                Re: template export question

                New_user wrote:[color=blue]
                >
                > Hello.
                >
                > Excerpt from ISO/IEC 14882 :
                > 14/6
                > A namespace-scope declaration or definition of ........skipped ...... a non-
                > inline member function of a class template or a static data member of a class
                > template may be preceded by the export keyword.
                >
                > and from http://www.comeaucomputing.com/4.3.0...5+/43stuff.txt :
                > A template must be declared export at both the point of definition and
                > the point of reference.
                >[/color]
                [snip][color=blue]
                >
                > How can I declare A<T>::fun in user.cpp as exported at the point of reference?[/color]

                If I understand you correctly you don't want to declare your templates with the
                export keyword at the point you are using them and still want them to be resolved
                as exported? If so, I would guess that would not do. I take 14/6 and 14/8 to mean
                that the first declaration of exported templates in /each/ of the translation units
                must use the export keyword; subsequent redeclarations or definitions do not need to
                use "export"; one and only one of the translation units must provide a definition.

                I am not quite sure and would like to confirm if the above is correct, for myself.

                It may sound ugly, but if you don't want to go the inclusion way I'd consider
                explicit instantiation.

                Denis

                Comment

                • Denis Remezov

                  #9
                  Re: template export question

                  New_user wrote:[color=blue]
                  >
                  > Hello.
                  >
                  > Excerpt from ISO/IEC 14882 :
                  > 14/6
                  > A namespace-scope declaration or definition of ........skipped ...... a non-
                  > inline member function of a class template or a static data member of a class
                  > template may be preceded by the export keyword.
                  >
                  > and from http://www.comeaucomputing.com/4.3.0...5+/43stuff.txt :
                  > A template must be declared export at both the point of definition and
                  > the point of reference.
                  >[/color]
                  [snip][color=blue]
                  >
                  > How can I declare A<T>::fun in user.cpp as exported at the point of reference?[/color]

                  If I understand you correctly you don't want to declare your templates with the
                  export keyword at the point you are using them and still want them to be resolved
                  as exported? If so, I would guess that would not do. I take 14/6 and 14/8 to mean
                  that the first declaration of exported templates in /each/ of the translation units
                  must use the export keyword; subsequent redeclarations or definitions do not need to
                  use "export"; one and only one of the translation units must provide a definition.

                  I am not quite sure and would like to confirm if the above is correct, for myself.

                  It may sound ugly, but if you don't want to go the inclusion way I'd consider
                  explicit instantiation.

                  Denis

                  Comment

                  • New_user

                    #10
                    Re: template export question

                    Hello, Denis.
                    [color=blue]
                    > If I understand you correctly you don't want to declare your templates with the
                    > export keyword at the point you are using them and still want them to be resolved
                    > as exported?[/color]

                    No. I just want to understand, how can I declare a non-inline
                    member-function of a class template (not a member template) or how can
                    I declare a static data-member of a class template as exported? It
                    seems to me, the only way is to declare class as exported. But
                    Standard says, that declaration of a non-inline member-function (or
                    static data-member) can be preceeded by the 'export' keyword.

                    Comment

                    • New_user

                      #11
                      Re: template export question

                      Hello, Denis.
                      [color=blue]
                      > If I understand you correctly you don't want to declare your templates with the
                      > export keyword at the point you are using them and still want them to be resolved
                      > as exported?[/color]

                      No. I just want to understand, how can I declare a non-inline
                      member-function of a class template (not a member template) or how can
                      I declare a static data-member of a class template as exported? It
                      seems to me, the only way is to declare class as exported. But
                      Standard says, that declaration of a non-inline member-function (or
                      static data-member) can be preceeded by the 'export' keyword.

                      Comment

                      Working...