求解答一个报错,能力不足没学明白

请问我这段代码这个报错怎么解决?
这是全部的代码:

#include 
#include 
#include  // 引入 std::out_of_range 异常

template<typename T>
class MyVector {
public:
    MyVector() : data(nullptr), size(0), capacity(0) {}

    // 复制构造函数
    MyVector(const MyVector& x) : data(nullptr), size(0), capacity(0) {
        *this = x;
    }

    ~MyVector() {
        clear();
    }

    // 赋值运算符
    MyVector& operator=(const MyVector& x) {
        if (this == &x) return *this;
        clear();

        // 复制数据
        capacity = x.capacity;
        size = x.size;
        data = new T[capacity];
        for (unsigned i = 0; i < size; i++) {
            data[i] = x.data[i];
        }

        return *this;
    }

    // 向量拼接
    MyVector operator+(const MyVector& x) const {
        MyVector result(*this);
        for (unsigned i = 0; i < x.size; i++) {
            result.push_back(x.data[i]);
        }
        return result;
    }

    // 输出流运算符
    friend std::ostream& operator<<(std::ostream& out, const MyVector& x) {
        for (unsigned i = 0; i < x.size; i++) {
            out << x.data[i] << " ";
        }
        return out;
    }

    // 下标运算符
    T& operator[](unsigned idx) {
        return data[idx];
    }

    // 清除向量
    void clear() {
        delete[] data;
        data = nullptr;
        size = 0;
        capacity = 0;
    }

    // 在尾部插入元素
    void push_back(const T& t) {
        if (size == capacity) {
            reserve(capacity + 16);
        }
        data[size++] = t;
    }

    // 弹出尾部元素
    void pop_back() {
        if (size > 0) {
            size--;
        }
    }

    // 访问元素
    T& at(unsigned idx) {
        if (idx < size) {
            return data[idx];
        }
        // 如果索引越界,抛出异常
        throw std::out_of_range("Index out of range");
    }

    // 获取向量大小
    unsigned int getSize() const {
        return size;
    }

    // 获取向量容量
    unsigned int getCapacity() const {
        return capacity;
    }

    // 判断向量是否为空
    bool empty() {
        return (size == 0);
    }

    // 访问首元素
    T& front() {
        return data[0];
    }

    // 访问尾元素
    T& back() {
        return data[size - 1];
    }

    // 在指定位置插入元素
    bool insert(unsigned pos, const T& t) {
        if (pos > size) {
            return false;
        }
        if (size == capacity) {
            reserve(capacity + 16);
        }
        for (unsigned i = size; i > pos; i--) {
            data[i] = data[i - 1];
        }
        data[pos] = t;
        size++;
        return true;
    }

    // 删除指定位置的元素
    bool erase(unsigned pos) {
        if (pos >= size) {
            return false;
        }
        for (unsigned i = pos; i < size - 1; i++) {
            data[i] = data[i + 1];
        }
        size--;
        return true;
    }

private:
    // 重新分配内存
    void reserve(unsigned newCapacity) {
        if (newCapacity <= capacity) {
            return;
        }
        T* newData = new T[newCapacity];
        if (data) {
            for (unsigned i = 0; i < size; i++) {
                newData[i] = data[i];
            }
            delete[] data;
        }
        data = newData;
        capacity = newCapacity;
    }

private:
    T* data;
    unsigned size;
    unsigned capacity;
};

// 自定义类型 Student
class Student {
public:
    Student(const std::string& id, const std::string& name,
            const std::string& schoolName, double discountRate)
        : id(id), name(name), schoolName(schoolName), discountRate(discountRate) {}

    std::string id;
    std::string name;
    std::string schoolName;
    double discountRate;
};

// 重载输出流运算符
std::ostream& operator<<(std::ostream& out, const Student& s) {
    out << "id: " << s.id << ", name: " << s.name
        << ", schoolName: " << s.schoolName
        << ", discountRate: " << s.discountRate;
    return out;
}

// 测试函数
void test() {
    // int 类型实例
    MyVector<int> intVec;
    for (int i = 0; i < 10; i++) {
        intVec.push_back(i);
    }
    std::cout << intVec << std::endl;

    // double 类型实例
    MyVector<double> doubleVec;
    for (int i = 0; i < 10; i++) {
        doubleVec.push_back(i * 1.5);
    }
    std::cout << doubleVec << std::endl;

    // 自定义类型 Student 实例
    MyVector studentVec;
    studentVec.push_back(Student("1001", "Tom", "PKU", 0.8));
    studentVec.push_back(Student("1002", "Jerry", "THU", 0.9));
    studentVec.push_back(Student("1003", "Jimmy", "Fudan", 0.7));
    std::cout << studentVec << std::endl;
}

int main() {
    test();

    return 0;
}

报错在148行,有截图

img


请教一下各位怎么解决,感激不尽。

给student写一个无参的构造函数。

编译报错不都说了吗 Student没有默认构造函数

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^