S
Shea Martin
I have a String class (I know I am re-inventing the wheel, yes I have
heard of boost, and of QString).
My copy constructor does a deep (strcpy) of the char *_buffer member.
I have a member function func(const String ¶m). When an actual
String is passed as the param this is nice and efficient.
I have a constructor which takes a const char* as an argument. And
performs a deep copy of the const char *buffer.
The issue occurrs when I make the following call:
func("this is the param");
The String(const char *buf) constructor is called, making a deep copy of
the data. Because func takes a const arg, it will never alter the
buffer, thus the deep copy of the const char * is needless, and could be
expensive.
Does anyone see an easy and somewhat safe design, to avoid the needless
copy's? Or is the only way to overload the methods to take a const
char* as well?
I think I already know the answer to this, but I would rather be safe
that sorry.
Thanks,
~S
heard of boost, and of QString).
My copy constructor does a deep (strcpy) of the char *_buffer member.
I have a member function func(const String ¶m). When an actual
String is passed as the param this is nice and efficient.
I have a constructor which takes a const char* as an argument. And
performs a deep copy of the const char *buffer.
The issue occurrs when I make the following call:
func("this is the param");
The String(const char *buf) constructor is called, making a deep copy of
the data. Because func takes a const arg, it will never alter the
buffer, thus the deep copy of the const char * is needless, and could be
expensive.
Does anyone see an easy and somewhat safe design, to avoid the needless
copy's? Or is the only way to overload the methods to take a const
char* as well?
I think I already know the answer to this, but I would rather be safe
that sorry.
Thanks,
~S