+ 1

Template specialization c++

https://sololearn.com/coach/889/?ref=app I’m having issues with this code. Can anyone help me ? It’s much appreciated. What I posted is the snippet I needed to produce but I’m not getting the right answers for test results. Please refer to the link posted for the full question. //your code goes here template < > class Div < string > { public: Div (string a, string b) { cout << sizeof(a) / sizeof(b) << endl; } };

23rd Nov 2021, 12:19 PM
Brent Tyson
Brent Tyson - avatar
2 odpowiedzi
+ 2
Use the size() or length() member function of the std::string class to get the length of the string, i.e. cout << a.size() / b.size() << endl; sizeof() returns the size of the class, not the length of the string managed by an object.
23rd Nov 2021, 1:58 PM
Shadow
Shadow - avatar
+ 1
Shadow thanks so much ! I just facepalmed myself; I Forgot to use dot notation. Much appreciated!
23rd Nov 2021, 3:51 PM
Brent Tyson
Brent Tyson - avatar