lundi 29 mars 2021

Best options for replacing std::string. - Is there a macro that can do this?

I currently have a header file. That does has the following signature

void foo::GetInfo(const std::string, std::string& str);

Now this signature needs to change to

void foo::GetInfo(const char*, char* str);

Now In my code there are bunch of scattered files that use this header file like this

std::string result;
inst->GetInfo(SomeString, result); //This will not work now

What I am looking for is a macro. A macro that I can wrap this statement in. Basically something that will do this to the above statement that fails

char* ptemp;
inst->GetInfo(SomeString.c_str(),ptemp);
result =std::string(ptemp);
delete* ptemp;

so basically a cleaner way of doing all the above. Preferably something I can just wrap the unworking string in

MagicMacro(inst->GetInfo(SomeString, result));

I am really not looking for exactly a macro, but something that might assist in cleaning up this entire code or atleast make it easier for me to do the change and less verbose. I am open to directions.

Aucun commentaire:

Enregistrer un commentaire