templated function with vector

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel L Elliott

    #1

    templated function with vector

    Hello,

    I am feeling very confused right now. The following code gives me an
    error:

    X.h:
    template <typename T>
    ILuint startImage(vect or<vector<T> > imageData);

    X.cpp:
    template<typena me T>
    void X::startImage(v ector<vector<T> > imageData){blah }

    test.cpp:
    vector<vector<d ouble> > testImage1(10);
    X.startImage(te stImage1);

    gcc 3.3.2 gives the following error:
    /home/dane/myLibraries/image/testDriver.cpp: 25: undefined reference to`unsigned X::startImage<d ouble>(std::vec tor<std::vector <double,
    std::allocator< double> >, std::allocator< std::vector<dou ble,std::alloca tor<double> > > >)'

    Am I not using templates correctly? It appears to have the correct
    function.

    Thank you very much for any assistance I might receive!

    - dan elliott


  • Victor Bazarov

    #2
    Re: templated function with vector

    Daniel L Elliott wrote:[color=blue]
    > I am feeling very confused right now. The following code gives me an
    > error:
    >
    > X.h:
    > template <typename T>
    > ILuint startImage(vect or<vector<T> > imageData);[/color]
    ^^^^^^
    [color=blue]
    > X.cpp:
    > template<typena me T>
    > void X::startImage(v ector<vector<T> > imageData){blah }[/color]
    ^^^^[color=blue]
    >
    > test.cpp:
    > vector<vector<d ouble> > testImage1(10);
    > X.startImage(te stImage1);
    >
    > gcc 3.3.2 gives the following error:
    > /home/dane/myLibraries/image/testDriver.cpp: 25: undefined reference to`unsigned X::startImage<d ouble>(std::vec tor<std::vector <double,
    > std::allocator< double> >, std::allocator< std::vector<dou ble,std::alloca tor<double> > > >)'
    >
    > Am I not using templates correctly? It appears to have the correct
    > function.[/color]

    It appears you don't.

    V

    Comment

    • Daniel L Elliott

      #3
      Re: templated function with vector

      On Fri, 29 Oct 2004 15:54:53 -0400, Victor Bazarov wrote:
      [color=blue]
      > Daniel L Elliott wrote:[color=green]
      >> I am feeling very confused right now. The following code gives me an
      >> error:
      >>
      >> X.h:
      >> template <typename T>
      >> ILuint startImage(vect or<vector<T> > imageData);[/color]
      > ^^^^^^
      >[color=green]
      >> X.cpp:
      >> template<typena me T>
      >> void X::startImage(v ector<vector<T> > imageData){blah }[/color]
      > ^^^^[color=green]
      >>
      >> test.cpp:
      >> vector<vector<d ouble> > testImage1(10);
      >> X.startImage(te stImage1);
      >>
      >> gcc 3.3.2 gives the following error:
      >> /home/dane/myLibraries/image/testDriver.cpp: 25: undefined reference to`unsigned X::startImage<d ouble>(std::vec tor<std::vector <double,
      >> std::allocator< double> >, std::allocator< std::vector<dou ble,std::alloca tor<double> > > >)'
      >>
      >> Am I not using templates correctly? It appears to have the correct
      >> function.[/color]
      >
      > It appears you don't.
      >
      > V[/color]

      I am not above total stupidity. I tried to simplify the example, and
      forgot to change ILuint startImage to void X::startImage in the example.

      It should read:

      X.h:
      template <typename T>
      void startImage(vect or<vector<T> > imageData);

      X.cpp:
      template<typena me T>
      void X::startImage(v ector<vector<T> > imageData){blah }

      test.cpp:
      vector<vector<d ouble> > testImage1(10);
      X.startImage(te stImage1);

      gcc 3.3.2 gives the following error:
      /home/dane/myLibraries/image/testDriver.cpp: 25: undefined reference to`unsigned X::startImage<d ouble>(std::vec tor<std::vector <double,
      std::allocator< double> >,
      std::allocator< std::vector<dou ble,std::alloca tor<double> > > >)'

      Thanks anyway.

      - dan

      Comment

      • John Harrison

        #4
        Re: templated function with vector


        "Daniel L Elliott" <dan_elliott_at _cox_dot_net@sp am_is_pathetic. com> wrote
        in message news:pan.2004.1 0.29.20.04.27.6 97158@spam_is_p athetic.com...[color=blue]
        > On Fri, 29 Oct 2004 15:54:53 -0400, Victor Bazarov wrote:
        >[color=green]
        >> Daniel L Elliott wrote:[color=darkred]
        >>> I am feeling very confused right now. The following code gives me an
        >>> error:
        >>>
        >>> X.h:
        >>> template <typename T>
        >>> ILuint startImage(vect or<vector<T> > imageData);[/color]
        >> ^^^^^^
        >>[color=darkred]
        >>> X.cpp:
        >>> template<typena me T>
        >>> void X::startImage(v ector<vector<T> > imageData){blah }[/color]
        >> ^^^^[color=darkred]
        >>>
        >>> test.cpp:
        >>> vector<vector<d ouble> > testImage1(10);
        >>> X.startImage(te stImage1);
        >>>
        >>> gcc 3.3.2 gives the following error:
        >>> /home/dane/myLibraries/image/testDriver.cpp: 25: undefined reference
        >>> to`unsigned X::startImage<d ouble>(std::vec tor<std::vector <double,
        >>> std::allocator< double> >,
        >>> std::allocator< std::vector<dou ble,std::alloca tor<double> > > >)'
        >>>
        >>> Am I not using templates correctly? It appears to have the correct
        >>> function.[/color]
        >>
        >> It appears you don't.
        >>
        >> V[/color]
        >
        > I am not above total stupidity. I tried to simplify the example, and
        > forgot to change ILuint startImage to void X::startImage in the example.
        >
        > It should read:
        >
        > X.h:
        > template <typename T>
        > void startImage(vect or<vector<T> > imageData);
        >
        > X.cpp:
        > template<typena me T>
        > void X::startImage(v ector<vector<T> > imageData){blah }
        >
        > test.cpp:
        > vector<vector<d ouble> > testImage1(10);
        > X.startImage(te stImage1);
        >
        > gcc 3.3.2 gives the following error:
        > /home/dane/myLibraries/image/testDriver.cpp: 25: undefined reference
        > to`unsigned X::startImage<d ouble>(std::vec tor<std::vector <double,
        > std::allocator< double> >,
        > std::allocator< std::vector<dou ble,std::alloca tor<double> > > >)'
        >
        > Thanks anyway.
        >
        > - dan[/color]

        I reckon this is the #1 post to this group.

        ALL TEMPLATE CODE MUST GO IN HEADER FILES.

        Most startimage out of X.cpp, put it in X.h and all will be well.

        Don't books on templates teach this? Where did you learn about templates
        that didn't mention this basic fact? And what about all the other people who
        post similar problems to yours. Please tell, I'm genuinely curious.

        john


        Comment

        • Daniel L Elliott

          #5
          Re: templated function with vector

          On Fri, 29 Oct 2004 21:16:48 +0100, John Harrison wrote:
          [color=blue]
          >
          > "Daniel L Elliott" <dan_elliott_at _cox_dot_net@sp am_is_pathetic. com> wrote
          > in message news:pan.2004.1 0.29.20.04.27.6 97158@spam_is_p athetic.com...[color=green]
          >> On Fri, 29 Oct 2004 15:54:53 -0400, Victor Bazarov wrote:
          >>[color=darkred]
          >>> Daniel L Elliott wrote:
          >>>> I am feeling very confused right now. The following code gives me an
          >>>> error:
          >>>>
          >>>> X.h:
          >>>> template <typename T>
          >>>> ILuint startImage(vect or<vector<T> > imageData);
          >>> ^^^^^^
          >>>
          >>>> X.cpp:
          >>>> template<typena me T>
          >>>> void X::startImage(v ector<vector<T> > imageData){blah }
          >>> ^^^^
          >>>>
          >>>> test.cpp:
          >>>> vector<vector<d ouble> > testImage1(10);
          >>>> X.startImage(te stImage1);
          >>>>
          >>>> gcc 3.3.2 gives the following error:
          >>>> /home/dane/myLibraries/image/testDriver.cpp: 25: undefined reference
          >>>> to`unsigned X::startImage<d ouble>(std::vec tor<std::vector <double,
          >>>> std::allocator< double> >,
          >>>> std::allocator< std::vector<dou ble,std::alloca tor<double> > > >)'
          >>>>
          >>>> Am I not using templates correctly? It appears to have the correct
          >>>> function.
          >>>
          >>> It appears you don't.
          >>>
          >>> V[/color]
          >>
          >> I am not above total stupidity. I tried to simplify the example, and
          >> forgot to change ILuint startImage to void X::startImage in the example.
          >>
          >> It should read:
          >>
          >> X.h:
          >> template <typename T>
          >> void startImage(vect or<vector<T> > imageData);
          >>
          >> X.cpp:
          >> template<typena me T>
          >> void X::startImage(v ector<vector<T> > imageData){blah }
          >>
          >> test.cpp:
          >> vector<vector<d ouble> > testImage1(10);
          >> X.startImage(te stImage1);
          >>
          >> gcc 3.3.2 gives the following error:
          >> /home/dane/myLibraries/image/testDriver.cpp: 25: undefined reference
          >> to`unsigned X::startImage<d ouble>(std::vec tor<std::vector <double,
          >> std::allocator< double> >,
          >> std::allocator< std::vector<dou ble,std::alloca tor<double> > > >)'
          >>
          >> Thanks anyway.
          >>
          >> - dan[/color]
          >
          > I reckon this is the #1 post to this group.
          >
          > ALL TEMPLATE CODE MUST GO IN HEADER FILES.
          >
          > Most startimage out of X.cpp, put it in X.h and all will be well.
          >
          > Don't books on templates teach this? Where did you learn about templates
          > that didn't mention this basic fact? And what about all the other people who
          > post similar problems to yours. Please tell, I'm genuinely curious.
          >
          > john[/color]

          Hey, thanks for the information. I am not sure how this fact has eluded
          me over the years. I even have books on c++ and they don't explictly say
          it (although their examples always put definitions in the header).

          You need to create a webpage entitled: function templates only belong in
          the header and have a bunch of people link to it so dummies like myself
          can find it via Google!

          - dan

          Comment

          • John Harrison

            #6
            Re: templated function with vector

            >>[color=blue][color=green]
            >> Don't books on templates teach this? Where did you learn about templates
            >> that didn't mention this basic fact? And what about all the other people
            >> who
            >> post similar problems to yours. Please tell, I'm genuinely curious.
            >>
            >> john[/color]
            >
            > Hey, thanks for the information. I am not sure how this fact has eluded
            > me over the years. I even have books on c++ and they don't explictly say
            > it (although their examples always put definitions in the header).
            >
            > You need to create a webpage entitled: function templates only belong in
            > the header and have a bunch of people link to it so dummies like myself
            > can find it via Google!
            >[/color]

            I guess its templates dirty little secret, people don't really like to talk
            about it.

            But it is in the FAQ,
            BlueOnyx: Open Source Web Hosting Solution - Powerful and Easy to Use


            john


            Comment

            • Default User

              #7
              Re: templated function with vector


              Daniel L Elliott wrote:

              [color=blue]
              > Hey, thanks for the information. I am not sure how this fact has[/color]
              eluded[color=blue]
              > me over the years. I even have books on c++ and they don't explictly[/color]
              say[color=blue]
              > it (although their examples always put definitions in the header).
              >
              > You need to create a webpage entitled: function templates only belong[/color]
              in[color=blue]
              > the header and have a bunch of people link to it so dummies like[/color]
              myself[color=blue]
              > can find it via Google![/color]


              Maybe even better would be to gather up all kinds of information on
              such problems that crop all the time, give it a catchy name like
              Frequently Asked Questions or sumpin.

              BlueOnyx: Open Source Web Hosting Solution - Powerful and Easy to Use

              Brian

              Comment

              • Daniel L Elliott

                #8
                Re: templated function with vector

                On Fri, 29 Oct 2004 13:52:20 -0700, Default User wrote:
                [color=blue]
                >
                > Daniel L Elliott wrote:
                >
                >[color=green]
                >> Hey, thanks for the information. I am not sure how this fact has[/color]
                > eluded[color=green]
                >> me over the years. I even have books on c++ and they don't explictly[/color]
                > say[color=green]
                >> it (although their examples always put definitions in the header).
                >>
                >> You need to create a webpage entitled: function templates only belong[/color]
                > in[color=green]
                >> the header and have a bunch of people link to it so dummies like[/color]
                > myself[color=green]
                >> can find it via Google![/color]
                >
                >
                > Maybe even better would be to gather up all kinds of information on
                > such problems that crop all the time, give it a catchy name like
                > Frequently Asked Questions or sumpin.
                >
                > http://www.parashift.com/c++-faq-lit...html#faq-34.12
                > Brian[/color]

                Brian, Jon, et al.

                Thanks for the link. It is full of excellent information. Stuff that I
                have been wondering about. Sadly, this webpage did not come up during my
                search. Search engines like Google typically use the size and location
                of text as a measure of its importance. If this is really such an
                annoyance, somebody should devote an entire page to it (no matter how
                ugly it is). I know I would have appreciated it.

                I also noticed that this is referred to as "the FAQ." Does this imply that
                this is the defacto, community C++ FAQ?

                Thanks again!

                - dan

                Comment

                • Victor Bazarov

                  #9
                  Re: templated function with vector

                  "Daniel L Elliott" <dan_elliott_at _cox_dot_net@sp am_is_pathetic. com>
                  wrote...[color=blue][color=green]
                  >> [..]
                  >> http://www.parashift.com/c++-faq-lit...html#faq-34.12
                  >> Brian[/color]
                  >
                  > Brian, Jon, et al.
                  >
                  > Thanks for the link. It is full of excellent information. Stuff that I
                  > have been wondering about. Sadly, this webpage did not come up during my
                  > search. Search engines like Google typically use the size and location
                  > of text as a measure of its importance. If this is really such an
                  > annoyance, somebody should devote an entire page to it (no matter how
                  > ugly it is). I know I would have appreciated it.
                  >
                  > I also noticed that this is referred to as "the FAQ." Does this imply that
                  > this is the defacto, community C++ FAQ?[/color]

                  It is de facto the FAQ for this newsgroup. It definitely is mentioned here
                  many times, so if you cared to read the newsgroup before posting to it, you
                  would see it. Also, http://groups.google.com/ is a very good source of
                  Q that have been A'ed already.

                  It's too late in comp.lang.c++, but if you ever decide to visit another NG,
                  try looking for the FAQ right away _before_ posting. It is always a good
                  idea to read FAQ. Saves you and others tons of time. Saves bandwidth too.

                  V


                  Comment

                  Working...