0
template <class type>
class BigInteger
{
private:
    const type base = (1 << sizeof(type) * 4) - 1;
    vector<type> digits;

public:
    friend istream& operator >> (istream& in, BigInteger<type> object);
};

istream& operator >> (istream& in, BigInteger<type> object)
{
    string input;
    in >> input;
    for (auto i = input.rbegin(); i != input.rend(); i++)
    {
        object.digits.push_back(*i);
    }
    return in;
}

Ошибка: E0020: идентификатор "type" не определен

Как исправить ее в моем случае?

Harry
  • 221,325
Learpcs
  • 747
  • 1
    template <class type> перед оператор не хватает – user7860670 Jul 17 '20 at 20:59
  • а она не будет каким-нибудь боком тоже просить указать тип (если бы допустим у меня была обычная функция, а не перезагрузка оператора)? или все это дело автоматизируется? – Learpcs Jul 17 '20 at 21:06
  • Нет, потому что компилятор сможет определить type по второму параметру, так же, как с обычной функцией. – HolyBlackCat Jul 17 '20 at 21:14
  • https://ru.stackoverflow.com/a/849917/312941 – tocic Jul 18 '20 at 05:59

1 Answers1

2

перегруженный оператор ввода у вас не является методом класса, этот оператор всего лишь дружественная функция к вашему классу, поэтому шаблон для него нужно прописывать отдельно, так как специализация функции не зависит от специализации класса и наоборот

template <class type>
class BigInteger
{
private:
  const type base = (1 << sizeof(type) * 4) - 1;
  vector<type> digits;

public: template <class type> // здесь новая строчка friend istream& operator >> (istream& in, BigInteger<type> object); };

template <class type> // и здесь istream& operator >> (istream& in, BigInteger<type> object) { string input; in >> input; for (auto i = input.rbegin(); i != input.rend(); i++) { object.digits.push_back(*i); } return in; }

Ildar
  • 2,802