deleted function

closed account (SECMoG1T)
Hi,I need some help with a certain code , okay The problem
Is I keep getting an error that I can't understand.
1
2
use of deleted function 'std::basic_ostream <char>::basic_ostream
                                                        (const std::basic_ostream<char>&)'


Problem is on the bind part in disp function.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
    #include <iostream>
    #include <vector>
    #include <functional>
    #include <algorithm>
   
    using namespace std;
    using namespace std::placeholders;
    
    ostream& print (int a, ostream& os, char c);
    // print display's a single integer.
    void disp (vector<int>& vec, ostream &os=cout);
    // disp uses print as a predicate to display a vector obj.


    int main ()
    {
       vector<int> myvec {1, 2, 3, 4, 5,6, 7, 8, 9};
       disp (myvec);

       return 0;
     }

    ostream& print (int a, ostream& os, char c)
    {
     return os<<a<<c;
    }
   
   void disp (vector<int>& vec, ostream &os)
    {
       cout <<"\n\n";
       for_each(vec.cbegin(), vec.cend(), bind(print,_1, os,'  '));
            ///error on bind.what's the problem? 
    }


Could I have deleted a library function somewhere without knowing?

Thanks in aadvance.
Last edited on
bind is passing the parameters by value, copy is disabled on std::ostream.
Use lambdas instead.
for_each(vec.cbegin(), vec.cend(), [&os](int a){print(a, os, ' ');});
closed account (SECMoG1T)
Well I see thanks @kbw , @minnippa copy is disabled on std::ostream. yea I guess
but how can I help myself here can bind take an ostream obj then?

@minnippa what is that  [&os](int a){print(a, os, ' ');} it looks like a function? well avn't
Heard of this , how is it a parameter ? I would like to understand those [&os] how did my
Print function pass to it's { }; I would really love to know this haha.
closed account (SECMoG1T)
Thank you very much @minnippa lemmi check them out they might be easier than they look and also
easier i hope haha,
Bravo.
closed account (SECMoG1T)
I stick to lambdas from now they are really cool lol.
Topic archived. No new replies allowed.