The line
string::difference_type i = LetterFrequency(mSample);
Constructs a LetterFrequency
object and attempts to assign it to a string::difference_type
variable (which is probably size_t
). As you would expect this doesn't work since there's no valid conversion between those types. It's the operator()(const string& str)
function that returns the actual count, not the constructor, so you need to call that function:
LetterFrequency lf(mSample);
string::difference_type i = lf(str);
// Or on one line:
// string::difference_type i = LetterFrequence(mSample)(str);
As an aside, I recommend you turn on compiler warnings (the -Wall
flag in g++). This would have helped alert you to the problem by warning you that the parameter str
was unused.