Your default constructor should not be explicit. I think explicitness may be the reason it can't convert std::string
to string_t
as well, but you erased that construtor from your snippet :vP .
This program compiles and runs fine with GCC 4.2:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class string_t :
#if defined(UNICODE) || defined(_UNICODE)
private std::basic_string<wchar_t>
#else
private std::basic_string<char>
#endif
{
public:
string_t() : basic_string<value_type>() {}
string_t( const basic_string<value_type>& str )
: basic_string<value_type>( str ) {}
virtual ~string_t() {}
using std::basic_string<value_type>::operator=; /* Line causing error */
std::vector<string_t> split( const string_t& delims )
{
std::vector<string_t> tokens;
for ( size_t pen = 0, next = 0; next != npos; pen = next + 1 ) {
next = find_first_of( delims, pen );
if ( pen != next ) tokens.push_back( substr( pen, next - pen ) );
}
return tokens;
}
template<class os>
friend os &operator<<(os &, string_t const&);
};
template< class os_t >
os_t &operator<<( os_t &os, string_t const &str ) {
return os << static_cast< string >(str);
}
int main( int argc, char ** argv ) {
vector<string_t> mytoks = string_t( argv[1] ).split( string( "_" ) );
for ( vector<string_t>::iterator it = mytoks.begin(); it != mytoks.end(); ++ it ) {
cerr << * it << endl;
}
return 0;
}