Im trying to create an array with the string::size member but its complaining at the declaration of "char message[msgSize]" that the expression did not evalute to a constant.
However it alows me to declare "msgSize".
How can this be? Why am i allowed to make a constant but i'm not allowed to use it to something that needs a const.
If the answer is that: "the size of the string could change" then the same argument can be made for using sizeof(), but that works.
const unsigned int msgSize =
saveAs.size() +
sizeof("NOTE| sent get request to: ") + 10;
char message[msgSize];
memset(message, 0, msgSize);
sprintf_s(message, msgSize,"NOTE| sent get request to: %s", saveAs.c_str());
_cRec->output(message);
sizeofcan be evaluated at compile time whilestring.size()cannot.constvariable and a constant expression.constis notconstexpr. If your compiler can figure aconstis a constant expression, as with thesizeof, it might let you use it as aconstexprvariable, but not if you throw in a runtime-only expression such assaveAs.size()std::stringwould be much more appropriate here.stringclass deal with that crap to the maximum extent possible. For example, why did you add10tomsgSize? Just to make extra sure that there was enough space for the message? Or does `output() actually write past the end of the passed in string?