Как сложить значение объекта класса с значением элемента массива?

У меня есть класс. У меня есть массив. Мне нужно сложить поле класса с значением элемента массива.

Если проще, что мне нужно:

int arr[]{ 1,2,3,4,5 };
    p2 = arr[3] + p2;

(прибавил к x, h и a четыре)

Выдрал такую перегрузку для оператора "+":

Pyramid operator +(double value, const Pyramid& t) {
    return { t.x + value, t.h + value, t.a + value };
}

В моем классе это не работает. Уже около часа сижу и не могу ничего с этим поделать. Как можно исправить проблему?

Интерфейс класса:

#include <iostream>
#include <fstream>
using namespace std;
class Pyramid {
public:
    double x, h, a; // x - сторона основания, h - высота, a - апофема
    friend Pyramid operator +(double value, const Pyramid& t);
    Pyramid() {
        x = h = a = 3;
    }
    Pyramid(double p, double k, double q) {
        x = p;
        h = k;
        a = q;
    }
    Pyramid(const Pyramid& obj) {
        this->x = obj.x;
        this->h = obj.h;
        this->a = obj.a;
    }
    Pyramid& operator=(Pyramid& obj) {
        if (this != &obj) {
            this->x = obj.x;
            this->h = obj.h;
            this->a = obj.a;
        }
        return *this;
    }
    Pyramid operator+(const Pyramid& b) {
        Pyramid temp;
        temp.x = this->x + b.x;
        temp.h = this->h + b.h;
        temp.a = this->a + b.a;
        return temp;
    }
    Pyramid& operator*(int chislo) {
        this->x *= chislo;
        this->h *= chislo;
        this->a *= chislo;
        return *this;
    }
    Pyramid& operator++(int value) {
        this->x++;
        this->h++;
        this->a++;
        return *this;
    }
    ~Pyramid() {
    }
private:
    double Sb = 10;
};


int main() {
    setlocale(0, "");


    return 0;
}

Pyramid operator +(double value, const Pyramid& t) {
    return { t.x + value, t.h + value, t.a + value };
}

Ответы (0 шт):