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

[976 byte] By [koresha@123] at [2007-11-26 8:56:32]
# 1

Do you have the only declaration of function BBReplaceStr? If there are more than one declaration you should specify the same default argument values in the each declaration.

For example the code below shows the same error:

[code]

template <typename T>

void foo(T p1, T p2);

template <typename T>

void foo(T p1, T p2 = 0)

{

}

[/code]

Atanasyan at 2007-7-6 22:55:39 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 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

koresha@123 at 2007-7-6 22:55:39 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3

1. You could install the latest patch: http://sunsolve.sun.com/pub-cgi/retrieve.pl?doc=fpatches%2F113817 (sparc) and/or http://sunsolve.sun.com/pub-cgi/retrieve.pl?doc=fpatches%2F113819 (intel)

2. You could use Sun Studio 11 (it's free): http://developers.sun.com/prodtech/cc/downloads/index.jsp

3. You could file a bug: http://bugs.sun.com/services/bugreport/index.jsp

Atanasyan at 2007-7-6 22:55:39 > top of Java-index,Development Tools,Solaris and Linux Development Tools...