Look at your code:
Solution word01;
string s1= "Hello caterpillar";
word01 s1;
cout << s1.reverseWords();
What do you expect that to do?
Solution word01;
Declares a variable called
word01
of type
Solution
string s1= "Hello caterpillar";
Declares a variable called
s1
of type
string
and assigns it a value - a string literal.
word01 s1;
Puts two variables side by side without doing anything with them ...
That last bit won't compile: the system has no idea what to do with it!
cout << s1.reverseWords();
Tries to call a method in the
string
class called
reverseWords
on the string in the variable
s1
. Since there is no method called
reverseWords
ion teh
string
class, that also won't compile.
reverseWords
is part of the
Solution
class, you need to use your instance of the class, call a method on that, and pass your string to it as a parameter:
Solution word01;
string s1= "Hello caterpillar";
cout << word01.reverseWords(s1);