0

Sololearn c++ 79.2 template specialists help pls

I’m stuck on this code pls help me understand it😭 Here’s my code: #include <iostream> using namespace std; template <class T> class Div { public: Div (T x, T y) { cout <<x / y<<endl; } }; //your code goes here template < > class Div<char> { public: Div (char x, char y) { cout <<x /y<<endl; } }; int main () { string a, b; cin >> a >> b; int x, y; cin >> x >> y; Div <string> d2(a, b); Div <int> d1(x, y); }

3rd Dec 2021, 4:03 PM
Boong Bing
3 odpowiedzi
0
What is the task to do there actually? Pls Mention problem description also.. error: string/string incompatible types for /
3rd Dec 2021, 4:07 PM
Jayakrishna 🇮🇳
0
You are given a Div class template, which has a constructor that takes two parameters and outputs their division. You need to specialize the class for strings, which should output the division of the lengths of the parameter strings, as the division operator is not defined for strings. Create the template specialization so that the code in main executes correctly.
4th Dec 2021, 4:13 PM
Boong Bing
0
//your code goes here template < > class Div<string> { public: Div (string x, string y) { cout <<x.length()/y.length()<<endl; } };
5th Dec 2021, 5:47 PM
Jayakrishna 🇮🇳