Error: in Default arguments with template
Hi ,
I am using Solaris5.8 with Sunstudio8 C++ 5.5 compiler
I have a header file in which I defined following lines of code
template <typename char_type>
I4 BBReplaceStr(char_type *str,
const char_type *searchStr,
const char_type *replaceStr = NULL,
BBLocale* bbLocale = G_CurrLocale)
{
I4 len = BBWorstCaseReplaceResultLen(BBStrlen(str), searchStr, replaceStr);
char_type tempBuf[1024];
char_type *tempPtr = tempBuf;
if (len > 1023)
tempPtr = new char_type[len + 1];
I4 ret = BBReplaceStr(str, tempPtr, len, searchStr, replaceStr, -1, bbLocale);
if (ret) BBStrcpy(str, tempPtr);
if (tempPtr != tempBuf)
DELETEARR(tempPtr);
return ret;
}
on compilation I am getting error in this file i.e
Error: Default arguments cannot be added in later declarations of the template.
Can any one one kown why this error is comming?
-riaj
# 2
Hi Climage,
my header file "xxx.h" contains following defination/declaration
template <typename char_type>
I4 BBReplaceStr(char_type *str,const char_type *searchStr,const char_type *replaceStr = NULL,BBLocale* bbLocale = G_CurrLocale)
[b]{[/b]I4 len = BBWorstCaseReplaceResultLen(BBStrlen(str), searchStr, replaceStr);
char_type tempBuf[1024];
char_type *tempPtr = tempBuf;
if (len > 1023)
tempPtr = new char_type[len + 1];
I4 ret = BBReplaceStr(str, tempPtr, len, searchStr, replaceStr, -1, bbLocale);
if (ret) BBStrcpy(str, tempPtr);
if (tempPtr != tempBuf)
DELETEARR(tempPtr);
return ret;
}
I4 BBReplaceStr(DIUString &str,const DIUChar *searchStr,const DIUChar *replaceStr = NULL);
I4 BBReplaceStr(string &str,const C1 *searchStr,const C1 *replaceStr = NULL,BBLocale* bbLocale = G_CurrLocale);
I4 BBReplaceStr(RWCString &str,const C1 *searchStr,const C1 *replaceStr = NULL);
On compiling with sunstudio C++(5.5) on solaris 5.8 I am getting following errors
"xxx.h" (at line number marked as bold )Default arguments cannot be added in later declarations of the template function in the same scope.
Is there any patch needed for compiler.
Please need your help.
-Riaj