overloading std::string operators requires template<> syntax ! Howto ?

Jul 12, 2012 at 10:29am
Hi all,

I need to overload a cast to u_int32_t of std::string. I wrote this :

string::operator u_int32_t() const {return 0;}

But the compiler says :

error: specializing member ‘std::basic_string<char>::operator u_int32_t’ requires ‘template<>’ syntax


I used to using templates for a while, but here, I really don't know how to manage it. Any idea please ?
Jul 12, 2012 at 10:32am
Conversion operators has to be class members. You can't add members outside the class definition so it's not possible to do what you are trying to do.
Last edited on Jul 12, 2012 at 10:33am
Jul 12, 2012 at 12:35pm
Thanks Peter87
Topic archived. No new replies allowed.