pullzed at static template member function

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

    pullzed at static template member function

    Hi,

    I want to declare a static template member function inside a non-template class, but MS C compiler always

    complains syntax error. I wonder if it is not allowed to do that? I tried SUN Forte compiler, it errored also.

    My class is like,

    class a{

    public:

    static template<class T> vector<T> getIntersection (vector<T>&, vector<T>&);

    };

    Could you point me what's wrong here?



  • Simon Saunders

    #2
    Re: pullzed at static template member function

    On Fri, 26 Sep 2003 12:23:12 -0600, Jee wrote:
    [color=blue]
    > Hi,
    >
    > I want to declare a static template member function inside a non-template class, but MS C compiler always
    >
    > complains syntax error. I wonder if it is not allowed to do that? I tried SUN Forte compiler, it errored also.
    >
    > My class is like,
    >
    > class a{
    >
    > public:
    >
    > static template<class T> vector<T> getIntersection (vector<T>&, vector<T>&);
    >
    > };
    >
    > Could you point me what's wrong here?
    >
    >[/color]

    class a
    {
    public:
    template<class T>
    static vector<T> getIntersection (vector<T>&, vector<T>&);
    };

    Comment

    • Jee

      #3
      Re: pullzed at static template member function

      Simon Saunders wrote:
      [color=blue]
      > On Fri, 26 Sep 2003 12:23:12 -0600, Jee wrote:
      >[color=green]
      > > Hi,
      > >
      > > I want to declare a static template member function inside a non-template class, but MS C compiler always
      > >
      > > complains syntax error. I wonder if it is not allowed to do that? I tried SUN Forte compiler, it errored also.
      > >
      > > My class is like,
      > >
      > > class a{
      > >
      > > public:
      > >
      > > static template<class T> vector<T> getIntersection (vector<T>&, vector<T>&);
      > >
      > > };
      > >
      > > Could you point me what's wrong here?
      > >
      > >[/color]
      >
      > class a
      > {
      > public:
      > template<class T>
      > static vector<T> getIntersection (vector<T>&, vector<T>&);
      > };[/color]

      I tried this, I got the same error, in MSC the error is
      error C2143: syntax error: missing ';' before '<'.

      and in Forte the error is
      Templates can only declare class and function.


      Still puzzled...


      Comment

      • Russell Hanneken

        #4
        Re: pullzed at static template member function

        "Jee" <jee@hotmail.co m> wrote in message
        news:3F74ADF7.F 1A87A82@hotmail .com...[color=blue]
        > Simon Saunders wrote:[color=green]
        > >
        > > class a
        > > {
        > > public:
        > > template<class T>
        > > static vector<T> getIntersection (vector<T>&, vector<T>&);
        > > };[/color]
        >
        > I tried this, I got the same error, in MSC the error is
        > error C2143: syntax error: missing ';' before '<'.
        >
        > and in Forte the error is
        > Templates can only declare class and function.[/color]

        Did you #include <vector>? Did you type "using namespace std;" or "using
        std::vector;"?

        This complete example compiles for me with Visual C++ .NET (2002):

        #include <vector>

        using std::vector;

        class a
        {
        public:
        template<class T>
        static vector<T> getIntersection (vector<T>&, vector<T>&);
        };

        --
        Russell Hanneken
        rghanneken@pobo x.com
        Remove the 'g' from my address to send me mail.



        Comment

        • DarkSpy

          #5
          Re: pullzed at static template member function

          right code is:
          class a{

          public:

          template<class T> static vector<T> getIntersection (vector<T>&, vector<T>&);

          };

          Jee <jee@hotmail.co m> wrote in message news:<3F748410. A6DD0BE2@hotmai l.com>...[color=blue]
          > Hi,
          >
          > I want to declare a static template member function inside a non-template class, but MS C compiler always
          >
          > complains syntax error. I wonder if it is not allowed to do that? I tried SUN Forte compiler, it errored also.
          >
          > My class is like,
          >
          > class a{
          >
          > public:
          >
          > static template<class T> vector<T> getIntersection (vector<T>&, vector<T>&);
          >
          > };
          >
          > Could you point me what's wrong here?
          >
          >
          >
          > --[/color]

          Comment

          • Kevin Goodsell

            #6
            Re: pullzed at static template member function

            DarkSpy wrote:
            [color=blue]
            > right code is:[/color]
            <snip>

            Please don't top-post. Read section 5 of the FAQ for posting guidelines.



            -Kevin
            --
            My email address is valid, but changes periodically.
            To contact me please use the address from a recent posting.

            Comment

            • DarkSpy

              #7
              Re: pullzed at static template member function

              "Russell Hanneken" <rghanneken@pob ox.com> wrote in message news:<qt2db.446 2$RW4.2478@news read4.news.pas. earthlink.net>. ..[color=blue]
              > "Jee" <jee@hotmail.co m> wrote in message
              > news:3F74ADF7.F 1A87A82@hotmail .com...[color=green]
              > > Simon Saunders wrote:[color=darkred]
              > > >
              > > > class a
              > > > {
              > > > public:
              > > > template<class T>
              > > > static vector<T> getIntersection (vector<T>&, vector<T>&);
              > > > };[/color]
              > >
              > > I tried this, I got the same error, in MSC the error is
              > > error C2143: syntax error: missing ';' before '<'.
              > >[/color][/color]

              sorry about my answer with above.

              if you got error, please check the MSC's version, maybe it is not
              enough modern to compile this code :-) or check the STL, please code:
              #include <vector>
              using namespace std; or using std::vector;

              Comment

              Working...