N
news.inode.at
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(char * source)
{
printf("Adddynamic: %d\n",strlen(source));
}
void AppendString(const char * source,unsigned len)
{
printf("AddStatic: %d\n",len);
}
myStr operator+=(char * source)
{
printf("Add Dynamic Length\n");
AppendString(source);
return *this;
}
__forceinline myStr operator+=(const 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(source,strlen(source));
return *this;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
myStr test;
test += "HHHHHHHHHHHHH"; //= 13 bytes = 0xd
test.AppendString("HHHHHHHHHHHHH",strlen("HHHHHHHHHHHHH"));
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(char * source)
{
printf("Adddynamic: %d\n",strlen(source));
}
void AppendString(const char * source,unsigned len)
{
printf("AddStatic: %d\n",len);
}
myStr operator+=(char * source)
{
printf("Add Dynamic Length\n");
AppendString(source);
return *this;
}
__forceinline myStr operator+=(const 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(source,strlen(source));
return *this;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
myStr test;
test += "HHHHHHHHHHHHH"; //= 13 bytes = 0xd
test.AppendString("HHHHHHHHHHHHH",strlen("HHHHHHHHHHHHH"));
return 0;
}
thx
franz