I have a class which has a constructor that takes a const char*. It is:
c::c(const char* str) {
a = 32;
f = 0;
data = new char[strlen(str)];
memcpy(data, str, strlen(str));
}
And a function which takes one of them:
int foo(c& cinst);
You can call this function either by passing it an instance of a c:
c cinst("asdf");
foo(cinst);
or, because we have explicit initialization, you can do:
foo("asdf");
which will make a c by passing the constructor “asdf” and then pass the resulting object to foo.
However, this seems like it might be quite a bit less efficient than just overloading foo to take a const char*. Is it worth doing the overload for the speed or is the performance impact so small that it’s a waste of space to make an overload? I’m trying to make my program as fast as possible, so speed is an important factor, so is size, but not so much.
What will
foobe doing with thatconst char*? If it’s just going to make it owncobject, then there’s no point.If it is going to use the
char*directly (and the existingfoojust pulled thechar*out of thecobject), then it would be better to write an overload.