Как обратится к типу шаблонного класса из другой функции?
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" не определен
Как исправить ее в моем случае?
Ответы (1 шт):
Автор решения: Ildar
→ Ссылка
перегруженный оператор ввода у вас не является методом класса, этот оператор всего лишь дружественная функция к вашему классу, поэтому шаблон для него нужно прописывать отдельно, так как специализация функции не зависит от специализации класса и наоборот
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;
}