Home > Back-end >  Is there a need for a string for overloading
Is there a need for a string for overloading

Time:03-06

Void fun (const char *);
Void fun (const STD: : string & amp;);

It is necessary to write a string version?

CodePudding user response:

Want to write write bai,

CodePudding user response:

Is there a need to go into this world time?

CodePudding user response:

I want to overload, but also feel a little more, choose difficult disease, heavy not overloaded

CodePudding user response:

Don't need to, you can directly use STD: : string. C_str () was introduced into the first function

CodePudding user response:

reference qq_40162781 reply: 3/f
I want to overload, but also feel a little more, choose difficult disease, you didn't overloaded

Does not exist, the string version called directly const char * version not finished?

CodePudding user response:

reference qq_40162781 reply: 3/f
I want to overload, but also feel a little more, choose difficult disease, you didn't overloaded

You need a function template and function template specialization

CodePudding user response:

Choose difficult disease, then according to the idea to do a, spend much time

CodePudding user response:

The
refer to the original poster qq_40162781 response:
void fun (const char *);
Void fun (const STD: : string & amp;);

It is necessary to write a string version?

If two functions must implement different overloading it's no need to discuss

If two functions to achieve exactly the same as
Don't overload
Don't just don't need to but should not be

If there are any changes you have to modify two function
Inadvertently missed will error

If the implementation is
 void fun (const STD: : string & amp; STR) {fun (STR) c_str ()); } 

Run a layer of function really not necessary


  • Related