mercredi 28 octobre 2015

Macking a user-defined class std::to_string(able)

I know it seems too much Java or C#. However, is it possible/good/wise to make my own class vaild as an input for the function std::to_string ? Example:

class my_class{
public:
std::string give_me_a_string_of_you() const{
    return "I am " + std::to_string(i);
}
int i;
};

void main(){
    my_class my_object;
    std::cout<< std::to_string(my_object);
}

If there is no such thing (and I think that), what is the best way to do it?

Aucun commentaire:

Enregistrer un commentaire