Sorry for this stupid question, but i am lost.
If i write an stringlib with += overload operators (no i do not, but my
thing is much more complicated) , and i have to precalculate the strlen() --
as seen in the example here
How do i solve this ?
struct myStr
{
private:
unsigned len;
unsigned size;
char string[100];
public:
myStr():
len(0),
size(0)
{
string[0] = 0;
}
~myStr() {}
void AppendString(ch ar * source)
{
printf("Adddyna mic: %d\n",strlen(so urce));
}
void AppendString(co nst char * source,unsigned len)
{
printf("AddStat ic: %d\n",len);
}
myStr operator+=(char * source)
{
printf("Add Dynamic Length\n");
AppendString(so urce);
return *this;
}
__forceinline myStr operator+=(cons t char * source)
{
printf("Add Static Length\n");
// HELP !!!! --why does he not inline the function and precalculate
strlen() at compiletime ? is there a method ?
like: templates or so ?
AppendString(so urce,strlen(sou rce));
return *this;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
myStr test;
test += "HHHHHHHHHHHHH" ; //= 13 bytes = 0xd
test.AppendStri ng("HHHHHHHHHHH HH",strlen("HHH HHHHHHHHHH"));
return 0;
}
thx
franz
If i write an stringlib with += overload operators (no i do not, but my
thing is much more complicated) , and i have to precalculate the strlen() --
as seen in the example here
How do i solve this ?
struct myStr
{
private:
unsigned len;
unsigned size;
char string[100];
public:
myStr():
len(0),
size(0)
{
string[0] = 0;
}
~myStr() {}
void AppendString(ch ar * source)
{
printf("Adddyna mic: %d\n",strlen(so urce));
}
void AppendString(co nst char * source,unsigned len)
{
printf("AddStat ic: %d\n",len);
}
myStr operator+=(char * source)
{
printf("Add Dynamic Length\n");
AppendString(so urce);
return *this;
}
__forceinline myStr operator+=(cons t char * source)
{
printf("Add Static Length\n");
// HELP !!!! --why does he not inline the function and precalculate
strlen() at compiletime ? is there a method ?
like: templates or so ?
AppendString(so urce,strlen(sou rce));
return *this;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
myStr test;
test += "HHHHHHHHHHHHH" ; //= 13 bytes = 0xd
test.AppendStri ng("HHHHHHHHHHH HH",strlen("HHH HHHHHHHHHH"));
return 0;
}
thx
franz
Comment