error: no matching function for call to 'std::reference_wrapper::reference_wrapper()












-2















Book and Article are derived classes from Medium.



Why am I getting this error when trying to insert Medium / Book / Article in the bibliography?



error: no matching function for call to '**std::reference_wrapper<Medium>::reference_wrapper()**


Compiler error



main.cc



#include <iostream>
using namespace std;
#include "Bibliography.h"
#include "Medium.h"
#include "Book.h"
#include "Article.h"

int main()
{
Bibliography p(1);
Medium m1("PN","I","Pasol nah",2017);
p.insert(m1);
cout << p;
return 0;
}




Bibliography.h



#ifndef BIBLIOGRAPHY_H_
#define BIBLIOGRAPHY_H_

#include "Medium.h"
#include "Article.h"
#include "Book.h"
#include <iostream>
#include <functional>
#include <vector>

class Bibliography
{
private:
int m_Size;
std::vector<std::reference_wrapper<Medium>> v;
int index;
public:
Bibliography(int size);
void insert(Medium m);
friend std::ostream& operator<<(std::ostream& out, const Bibliography &b1);
};

#endif




Bibliography.cc



#include "Bibliography.h"

Bibliography::Bibliography(int size)
{
std::cout << "Bibliography created n";
m_Size = size;
v.resize(m_Size);
index = 0;
}

void Bibliography::insert(Medium m)
{
v.push_back(m);
}

std::ostream& operator<<(std::ostream& out, const Bibliography &b1)
{
for (Medium &Medium : b1.v)
{
out << Medium.toString() << std::endl;
}
return out;
}









share|improve this question





























    -2















    Book and Article are derived classes from Medium.



    Why am I getting this error when trying to insert Medium / Book / Article in the bibliography?



    error: no matching function for call to '**std::reference_wrapper<Medium>::reference_wrapper()**


    Compiler error



    main.cc



    #include <iostream>
    using namespace std;
    #include "Bibliography.h"
    #include "Medium.h"
    #include "Book.h"
    #include "Article.h"

    int main()
    {
    Bibliography p(1);
    Medium m1("PN","I","Pasol nah",2017);
    p.insert(m1);
    cout << p;
    return 0;
    }




    Bibliography.h



    #ifndef BIBLIOGRAPHY_H_
    #define BIBLIOGRAPHY_H_

    #include "Medium.h"
    #include "Article.h"
    #include "Book.h"
    #include <iostream>
    #include <functional>
    #include <vector>

    class Bibliography
    {
    private:
    int m_Size;
    std::vector<std::reference_wrapper<Medium>> v;
    int index;
    public:
    Bibliography(int size);
    void insert(Medium m);
    friend std::ostream& operator<<(std::ostream& out, const Bibliography &b1);
    };

    #endif




    Bibliography.cc



    #include "Bibliography.h"

    Bibliography::Bibliography(int size)
    {
    std::cout << "Bibliography created n";
    m_Size = size;
    v.resize(m_Size);
    index = 0;
    }

    void Bibliography::insert(Medium m)
    {
    v.push_back(m);
    }

    std::ostream& operator<<(std::ostream& out, const Bibliography &b1)
    {
    for (Medium &Medium : b1.v)
    {
    out << Medium.toString() << std::endl;
    }
    return out;
    }









    share|improve this question



























      -2












      -2








      -2


      0






      Book and Article are derived classes from Medium.



      Why am I getting this error when trying to insert Medium / Book / Article in the bibliography?



      error: no matching function for call to '**std::reference_wrapper<Medium>::reference_wrapper()**


      Compiler error



      main.cc



      #include <iostream>
      using namespace std;
      #include "Bibliography.h"
      #include "Medium.h"
      #include "Book.h"
      #include "Article.h"

      int main()
      {
      Bibliography p(1);
      Medium m1("PN","I","Pasol nah",2017);
      p.insert(m1);
      cout << p;
      return 0;
      }




      Bibliography.h



      #ifndef BIBLIOGRAPHY_H_
      #define BIBLIOGRAPHY_H_

      #include "Medium.h"
      #include "Article.h"
      #include "Book.h"
      #include <iostream>
      #include <functional>
      #include <vector>

      class Bibliography
      {
      private:
      int m_Size;
      std::vector<std::reference_wrapper<Medium>> v;
      int index;
      public:
      Bibliography(int size);
      void insert(Medium m);
      friend std::ostream& operator<<(std::ostream& out, const Bibliography &b1);
      };

      #endif




      Bibliography.cc



      #include "Bibliography.h"

      Bibliography::Bibliography(int size)
      {
      std::cout << "Bibliography created n";
      m_Size = size;
      v.resize(m_Size);
      index = 0;
      }

      void Bibliography::insert(Medium m)
      {
      v.push_back(m);
      }

      std::ostream& operator<<(std::ostream& out, const Bibliography &b1)
      {
      for (Medium &Medium : b1.v)
      {
      out << Medium.toString() << std::endl;
      }
      return out;
      }









      share|improve this question
















      Book and Article are derived classes from Medium.



      Why am I getting this error when trying to insert Medium / Book / Article in the bibliography?



      error: no matching function for call to '**std::reference_wrapper<Medium>::reference_wrapper()**


      Compiler error



      main.cc



      #include <iostream>
      using namespace std;
      #include "Bibliography.h"
      #include "Medium.h"
      #include "Book.h"
      #include "Article.h"

      int main()
      {
      Bibliography p(1);
      Medium m1("PN","I","Pasol nah",2017);
      p.insert(m1);
      cout << p;
      return 0;
      }




      Bibliography.h



      #ifndef BIBLIOGRAPHY_H_
      #define BIBLIOGRAPHY_H_

      #include "Medium.h"
      #include "Article.h"
      #include "Book.h"
      #include <iostream>
      #include <functional>
      #include <vector>

      class Bibliography
      {
      private:
      int m_Size;
      std::vector<std::reference_wrapper<Medium>> v;
      int index;
      public:
      Bibliography(int size);
      void insert(Medium m);
      friend std::ostream& operator<<(std::ostream& out, const Bibliography &b1);
      };

      #endif




      Bibliography.cc



      #include "Bibliography.h"

      Bibliography::Bibliography(int size)
      {
      std::cout << "Bibliography created n";
      m_Size = size;
      v.resize(m_Size);
      index = 0;
      }

      void Bibliography::insert(Medium m)
      {
      v.push_back(m);
      }

      std::ostream& operator<<(std::ostream& out, const Bibliography &b1)
      {
      for (Medium &Medium : b1.v)
      {
      out << Medium.toString() << std::endl;
      }
      return out;
      }






      c++ stdvector reference-wrapper






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 25 '18 at 15:03









      vallismortis

      3,621104265




      3,621104265










      asked Dec 16 '17 at 19:16









      Gicu MironicaGicu Mironica

      61




      61
























          1 Answer
          1






          active

          oldest

          votes


















          1














          You should not use reference_wrapper in vector, because vector can keep objects which have default constructor, reference_wrapper doesn't have it, look at these constructors of reference_wrapper:



          initialization (1)  
          reference_wrapper (type& ref) noexcept;
          reference_wrapper (type&&) = delete;
          copy (2)
          reference_wrapper (const reference_wrapper& x) noexcept;


          In this line



          v.resize(m_Size); 


          you want to create m_Size reference_wrapperobjects, but default constructor for reference_wrapper doesn't exist, and code cannot be compiled.



          You can use reference_wrapper with vector but you get compilation error
          when method of vector is called which needs default constructor to be defined.






          share|improve this answer


























          • Is this really true? The C++ Reference specifically uses a vector as the example usage of a reference_wrapper.

            – vallismortis
            Nov 25 '18 at 14:23






          • 1





            In the example you posted there is a list with 10 elements. list<int> l(10); vector keeps reference_wrapper<int>, when this vector is created v(l.begin(),l.end()) constructor of reference_wrapper is called which takes Lvalues as parameter, storing pointer to these Lvalues, so in this case vector+reference_wrapper works. But resize on vector cannot be called because resize calls default ctor for reference_wrapper. reference_wrapper needs to store pointer to some object (reference needs to be initialized). Therefore default ctor for reference_wrapper doesn't exist.

            – rafix07
            Nov 25 '18 at 14:43











          • Much appreciated. The C++ Reference would be more helpful if it included examples like this.

            – vallismortis
            Nov 25 '18 at 15:00











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47849130%2ferror-no-matching-function-for-call-to-stdreference-wrappermediumreferen%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You should not use reference_wrapper in vector, because vector can keep objects which have default constructor, reference_wrapper doesn't have it, look at these constructors of reference_wrapper:



          initialization (1)  
          reference_wrapper (type& ref) noexcept;
          reference_wrapper (type&&) = delete;
          copy (2)
          reference_wrapper (const reference_wrapper& x) noexcept;


          In this line



          v.resize(m_Size); 


          you want to create m_Size reference_wrapperobjects, but default constructor for reference_wrapper doesn't exist, and code cannot be compiled.



          You can use reference_wrapper with vector but you get compilation error
          when method of vector is called which needs default constructor to be defined.






          share|improve this answer


























          • Is this really true? The C++ Reference specifically uses a vector as the example usage of a reference_wrapper.

            – vallismortis
            Nov 25 '18 at 14:23






          • 1





            In the example you posted there is a list with 10 elements. list<int> l(10); vector keeps reference_wrapper<int>, when this vector is created v(l.begin(),l.end()) constructor of reference_wrapper is called which takes Lvalues as parameter, storing pointer to these Lvalues, so in this case vector+reference_wrapper works. But resize on vector cannot be called because resize calls default ctor for reference_wrapper. reference_wrapper needs to store pointer to some object (reference needs to be initialized). Therefore default ctor for reference_wrapper doesn't exist.

            – rafix07
            Nov 25 '18 at 14:43











          • Much appreciated. The C++ Reference would be more helpful if it included examples like this.

            – vallismortis
            Nov 25 '18 at 15:00
















          1














          You should not use reference_wrapper in vector, because vector can keep objects which have default constructor, reference_wrapper doesn't have it, look at these constructors of reference_wrapper:



          initialization (1)  
          reference_wrapper (type& ref) noexcept;
          reference_wrapper (type&&) = delete;
          copy (2)
          reference_wrapper (const reference_wrapper& x) noexcept;


          In this line



          v.resize(m_Size); 


          you want to create m_Size reference_wrapperobjects, but default constructor for reference_wrapper doesn't exist, and code cannot be compiled.



          You can use reference_wrapper with vector but you get compilation error
          when method of vector is called which needs default constructor to be defined.






          share|improve this answer


























          • Is this really true? The C++ Reference specifically uses a vector as the example usage of a reference_wrapper.

            – vallismortis
            Nov 25 '18 at 14:23






          • 1





            In the example you posted there is a list with 10 elements. list<int> l(10); vector keeps reference_wrapper<int>, when this vector is created v(l.begin(),l.end()) constructor of reference_wrapper is called which takes Lvalues as parameter, storing pointer to these Lvalues, so in this case vector+reference_wrapper works. But resize on vector cannot be called because resize calls default ctor for reference_wrapper. reference_wrapper needs to store pointer to some object (reference needs to be initialized). Therefore default ctor for reference_wrapper doesn't exist.

            – rafix07
            Nov 25 '18 at 14:43











          • Much appreciated. The C++ Reference would be more helpful if it included examples like this.

            – vallismortis
            Nov 25 '18 at 15:00














          1












          1








          1







          You should not use reference_wrapper in vector, because vector can keep objects which have default constructor, reference_wrapper doesn't have it, look at these constructors of reference_wrapper:



          initialization (1)  
          reference_wrapper (type& ref) noexcept;
          reference_wrapper (type&&) = delete;
          copy (2)
          reference_wrapper (const reference_wrapper& x) noexcept;


          In this line



          v.resize(m_Size); 


          you want to create m_Size reference_wrapperobjects, but default constructor for reference_wrapper doesn't exist, and code cannot be compiled.



          You can use reference_wrapper with vector but you get compilation error
          when method of vector is called which needs default constructor to be defined.






          share|improve this answer















          You should not use reference_wrapper in vector, because vector can keep objects which have default constructor, reference_wrapper doesn't have it, look at these constructors of reference_wrapper:



          initialization (1)  
          reference_wrapper (type& ref) noexcept;
          reference_wrapper (type&&) = delete;
          copy (2)
          reference_wrapper (const reference_wrapper& x) noexcept;


          In this line



          v.resize(m_Size); 


          you want to create m_Size reference_wrapperobjects, but default constructor for reference_wrapper doesn't exist, and code cannot be compiled.



          You can use reference_wrapper with vector but you get compilation error
          when method of vector is called which needs default constructor to be defined.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 16 '17 at 20:43

























          answered Dec 16 '17 at 19:39









          rafix07rafix07

          7,9381714




          7,9381714













          • Is this really true? The C++ Reference specifically uses a vector as the example usage of a reference_wrapper.

            – vallismortis
            Nov 25 '18 at 14:23






          • 1





            In the example you posted there is a list with 10 elements. list<int> l(10); vector keeps reference_wrapper<int>, when this vector is created v(l.begin(),l.end()) constructor of reference_wrapper is called which takes Lvalues as parameter, storing pointer to these Lvalues, so in this case vector+reference_wrapper works. But resize on vector cannot be called because resize calls default ctor for reference_wrapper. reference_wrapper needs to store pointer to some object (reference needs to be initialized). Therefore default ctor for reference_wrapper doesn't exist.

            – rafix07
            Nov 25 '18 at 14:43











          • Much appreciated. The C++ Reference would be more helpful if it included examples like this.

            – vallismortis
            Nov 25 '18 at 15:00



















          • Is this really true? The C++ Reference specifically uses a vector as the example usage of a reference_wrapper.

            – vallismortis
            Nov 25 '18 at 14:23






          • 1





            In the example you posted there is a list with 10 elements. list<int> l(10); vector keeps reference_wrapper<int>, when this vector is created v(l.begin(),l.end()) constructor of reference_wrapper is called which takes Lvalues as parameter, storing pointer to these Lvalues, so in this case vector+reference_wrapper works. But resize on vector cannot be called because resize calls default ctor for reference_wrapper. reference_wrapper needs to store pointer to some object (reference needs to be initialized). Therefore default ctor for reference_wrapper doesn't exist.

            – rafix07
            Nov 25 '18 at 14:43











          • Much appreciated. The C++ Reference would be more helpful if it included examples like this.

            – vallismortis
            Nov 25 '18 at 15:00

















          Is this really true? The C++ Reference specifically uses a vector as the example usage of a reference_wrapper.

          – vallismortis
          Nov 25 '18 at 14:23





          Is this really true? The C++ Reference specifically uses a vector as the example usage of a reference_wrapper.

          – vallismortis
          Nov 25 '18 at 14:23




          1




          1





          In the example you posted there is a list with 10 elements. list<int> l(10); vector keeps reference_wrapper<int>, when this vector is created v(l.begin(),l.end()) constructor of reference_wrapper is called which takes Lvalues as parameter, storing pointer to these Lvalues, so in this case vector+reference_wrapper works. But resize on vector cannot be called because resize calls default ctor for reference_wrapper. reference_wrapper needs to store pointer to some object (reference needs to be initialized). Therefore default ctor for reference_wrapper doesn't exist.

          – rafix07
          Nov 25 '18 at 14:43





          In the example you posted there is a list with 10 elements. list<int> l(10); vector keeps reference_wrapper<int>, when this vector is created v(l.begin(),l.end()) constructor of reference_wrapper is called which takes Lvalues as parameter, storing pointer to these Lvalues, so in this case vector+reference_wrapper works. But resize on vector cannot be called because resize calls default ctor for reference_wrapper. reference_wrapper needs to store pointer to some object (reference needs to be initialized). Therefore default ctor for reference_wrapper doesn't exist.

          – rafix07
          Nov 25 '18 at 14:43













          Much appreciated. The C++ Reference would be more helpful if it included examples like this.

          – vallismortis
          Nov 25 '18 at 15:00





          Much appreciated. The C++ Reference would be more helpful if it included examples like this.

          – vallismortis
          Nov 25 '18 at 15:00




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47849130%2ferror-no-matching-function-for-call-to-stdreference-wrappermediumreferen%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'