Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

Default argument in function causes error

Hi,

I'm using a default argument in a function which compiles in project 1, but not in project 2.  I'm using Borland c++ 6.

StringTools.h:
-------------------
String removeLeadingZeros(String stInput, bool removeLastZero=true);

StringTools.cpp
-------------------
String removeLeadingZeros(String stInput, bool removeLastZero)
{
        if(stInput.Length()<1) return "";
        bool removedAZero = false;
        while(stInput.Length()>0)
        {
                if(stInput.c_str()[0]=='0')
                {
                        stInput.Delete(1,1);
                        removedAZero = true;
                }
                else break;
        }
        if(removedAZero==true && removeLastZero==false && stInput=="") stInput = "0";//if we removed the last zero, then empty string must be "0"
        return stInput;
}


While compiling this is the error I get:
[C++ Error] StringTools.h(11): E2149 Default argument value redeclared

Is this a compiler/project setting, 'cause in the other project it works fine.
Thanks for any help.
0
cleaverX
Asked:
cleaverX
1 Solution
 
JensUniwebCommented:
I would guess that you have the function declared in multiple places and with diffrent default values.
0
 
itsmeandnobodyelseCommented:
It looks as if you have included StringTools.h twice. The second include might give you this error.

Try to make your header safe by using

#ifndef STRINGTOOLS_H           // this protects your header beeing included twice
#define STRINGTOOLS_H          

// here you should put the contents of your header


#endif   // that is last statement of your header


Hope, that helps

Alex
0
 
cleaverXAuthor Commented:
Thanks for the help!  The file got included more than once and I forgot the define...
Greetz
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now