Recently, I have been wanting to define a subclass spstring of std::string. It declared in spstr.h:
#include <cctype>
#include <string>
#include <algorithm>
#include <sstream>
#include <stdint.h>
#include <xstring>
class spstring : public std::string {
public:
spstring(std::string s):std::string(s){} //Declare the constructor
int stoi(); //Declare stoi
spstring Spstring(std::string s); ////Declare mandatory conversion function
};
spstring spstring::Spstring(std::string s)
{
spstring spstr(s);
return(spstr);
}
However, when tested in main.cpp:
spstring byteaddstr(std::string(argv[4])); //convertchar* to spstring
int byteadd;
byteadd=byteaddstr.stoi(); //call byteaddstr.stoi
it failed to be complied for:
error C2228: left of “.stoi” must have class/struct/union
Sounds strange, since byteaddstr indeed an instance of spstring, why cannot call its member function?