How do i inherit a template class in c++ | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 3

How do i inherit a template class in c++

I'm practicing, and I am trying inherit a class template but the code get error, how to solve it? https://code.sololearn.com/cKhbglUg872w/?ref=app

21st Feb 2023, 6:32 PM
Andres Gómez
Andres Gómez - avatar
3 ответов
+ 4
Op has two type parameters. Upon inheriting you pass none. You have to specify what Op's T and S are supposed to be when declaring class Calc. Class Calc has one type parameter which you may pass on to Op. So, something like this is probably what you are looking for: template <class T> class Calc : public Op<T, int> { ... };
21st Feb 2023, 7:00 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 6
Thank you
21st Feb 2023, 7:23 PM
Andres Gómez
Andres Gómez - avatar
+ 3
You're welcome.
21st Feb 2023, 7:46 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar