c ++是什么导致我的程序出现此错误?

问题描述 投票:0回答:1

我创建了这个istream函数,该函数在将向量传递给class Person的构造函数之前先验证输入,但是我注意到,每当我把p=Person(vect);行放入时,都会出现以下错误:

std :: ios_base :: ios_base(const std :: ios_base)是私有的

这是我的istream功能代码

    std::istream & operator >> (istream & in, Person & p)
    {
    string title;
    getline (in, title);
    vector<double> vect;
    double convertToDouble;
    size_t i = 0;
    for (; i < title.length (); i++)
     {
       if (isdigit(title[i]))
         {
           convertToDouble = title[i] - '0';
           vect.push_back(found);
         }

    }
   if(vect.size()>0)
    {
      p=Person(vect);  //line of error!
    }
   return in;
  }

这是我的构造函数在Person class中的外观>

Person(const vector<double>& vect) : vec(vect)

我在做什么错?

我创建了这个istream函数,该函数在将向量传递给Person类的构造函数之前先验证输入,但是我注意到,每当我将p = Person(vect)行放置时;我得到了...

c++ vector stream
1个回答
-3
投票

您必须为Person定义一个副本构造函数,例如:人(const Person&prsn){...}

© www.soinside.com 2019 - 2024. All rights reserved.