Thinking in C++

Discussion in 'C++' started by Alex Buell, Dec 4, 2007.

  1. Alex Buell

    Alex Buell Guest

    Could anyone tell me why this program taken from the Thinking in C++
    book won't compile with GCC 4.1.2? Here's the error:

    C++ Binder.o
    Binder.cpp: In function ‘int main()’:
    Binder.cpp:19: error: no matching function for call to ‘copy
    (<unresolved overloaded function type>,
    __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int>
    > >, std::eek:stream_iterator<int, char, std::char_traits<char>
    > >>&)’ /usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g+
    > >>+-v4/bits/stl_algobase.h:376: note: candidates are: _OutputIterator
    > >>std::copy(_InputIterator, _InputIterator, _OutputIterator) [with
    > >>_InputIterator = __gnu_cxx::__normal_iterator<int*,
    > >>std::vector<int, std::allocator<int> > >, _OutputIterator =
    > >>std::eek:stream_iterator<int, char, std::char_traits<char> >]


    And here's the program itself:

    #include <algorithm>
    #include <cstdlib>
    #include <ctime>
    #include <functional>
    #include <iostream>
    #include <iterator>
    #include <vector>
    #include "Generators.h"

    using namespace std;

    int main()
    {
    ostream_iterator<int> out(cout, " ");
    vector<int> v(15);
    srand(time(0));

    generate(v.begin(), v.end(), URandGen(20));
    copy(v.begin, v.end(), out);
    transform(v.begin(), v.end(), v.begin(), bind2nd(multiplies<int>
    (), 10)); copy(v.begin(), v.end(), out); }

    The odd thing is that if I comment out the first copy() call, it
    compiles just fine?

    Thanks,
    Alex
    --
    http://www.munted.org.uk

    Fearsome grindings.
     
    Alex Buell, Dec 4, 2007
    #1
    1. Advertising

  2. Alex Buell wrote:
    > copy(v.begin, v.end(), out);


    Did you mean to *call* 'begin'? Compare to the second call to
    'copy' here:

    > [..]


    > copy(v.begin(), v.end(), out); }



    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Dec 4, 2007
    #2
    1. Advertising

  3. Alex Buell

    Alex Buell Guest

    On Tue, 4 Dec 2007 16:08:53 -0500, I waved a wand and this message
    magically appears in front of Victor Bazarov:

    > > copy(v.begin, v.end(), out);

    >
    > Did you mean to *call* 'begin'? Compare to the second call to
    > 'copy' here:
    >
    > > [..]

    >
    > > copy(v.begin(), v.end(), out); }


    Oh, no... I forgot the ()! My apologies for making such a stupid
    mistake!

    Regards,
    Alex
    --
    http://www.munted.org.uk

    Fearsome grindings.
     
    Alex Buell, Dec 4, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Homa
    Replies:
    7
    Views:
    456
    John Saunders
    Nov 16, 2003
  2. Simon Harris

    Thinking the right way?

    Simon Harris, May 31, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    380
    Simon Harris
    Jun 2, 2004
  3. Giammarco
    Replies:
    2
    Views:
    407
    Giammarco
    Aug 25, 2005
  4. Replies:
    14
    Views:
    669
    Chris Botha
    Nov 13, 2005
  5. optimistx

    Linear thinking vs essential thinking

    optimistx, Oct 28, 2009, in forum: Javascript
    Replies:
    4
    Views:
    185
    Dr J R Stockton
    Oct 29, 2009
Loading...

Share This Page