Нет подходящей функции для вызова вектора - PullRequest
0 голосов
/ 30 апреля 2020

У меня есть класс Registration, который читает первую строку ввода из файла и отправляет его в другой класс Result для чтения в остальном заданным c способом. Я хочу добиться этого, используя собственный векторный класс. Я объявляю мой Вектор результатов регистрации как частную переменную следующим образом:

Vector<Result> results;

Вот как я использую его при регистрации. cpp:

void Registration::readFile(istream &input){

    long studentid1;
    unsigned semester1;


    input >> studentid1 >> semester1 >> count;



    SetStudentID(studentid1);
    SetSemester(semester1);


    for(unsigned i = 0; i < count; i++){

        results.add(&input); //sending the rest of the input to my dynamic array of Results
    }

}

Я получаю ошибка: no matching function for call to 'Vector<Result>::add(std::istream*)'| в строке results.add(&input) при регистрации. cpp.

My Vector.h:

#ifndef VECTOR_H
#define VECTOR_H
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

template <class T>
class Vector
{
    public:
        Vector(int size = 10);
        ~Vector();

        void initialize(unsigned from = 0);
        void expand();
        void add(const T &obj);
        int size() const{return this->nrofel;}

        T& operator[](const int index);
        const T& operator[](const int index) const;


    private:
        T **data;
        unsigned capacity;
        unsigned nrofel;

};

template <class T>
Vector<T>::Vector(int size){

    this->capacity = size;
    this->nrofel = 0;
    this->data = new T*[this->capacity];

    this->initialize();

}

template <class T>
T& Vector<T>::operator[](int index){

    if(index < 0 || index > this->nrofel){

        throw ("Bad index");

    }

    return *this->data[index];

}

template <class T>
const T& Vector<T>::operator[](int index) const{

    if(index < 0 || index > this->nrofel){

        throw ("Bad index");

    }

    return *this->data[index];

}

template <class T>
void Vector<T>::initialize(unsigned from){

    for(size_t i = from; i < this->capacity; i++){

        this->data[i] = nullptr;

    }

}

template <class T>
Vector<T>::~Vector(){

    for(size_t i = 0; i < capacity; i++){

        delete this->data[i];

    }
    delete[]this->data;
}


template <class T>
void Vector<T>::expand(){

    this->capacity *= 2;

    T** tempData = new T*[this->capacity];

    for(size_t i = 0; i < this->nrofel; i++){

        tempData[i] = new T(*this->data[i]);

    }

    for(size_t i = 0; i < this->nrofel; i++){

       delete this->data[i];

    }

    delete[] data;

    this->data = tempData;

    this->initialize(this->nrofel);

}

template <class T>
void Vector<T>::add(const T &obj){

    if(this->nrofel >= this->capacity){

        this->expand();

    }

    this->data[this->nrofel++] = new T(obj);

}



#endif // VECTOR_H
...