Solved

Default argument in function causes error

Posted on 2003-11-24
3
247 Views
Last Modified: 2010-08-05
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
Comment
Question by:cleaverX
3 Comments
 
LVL 2

Expert Comment

by:JensUniweb
ID: 9809149
I would guess that you have the function declared in multiple places and with diffrent default values.
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 50 total points
ID: 9809175
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
 

Author Comment

by:cleaverX
ID: 9809427
Thanks for the help!  The file got included more than once and I forgot the define...
Greetz
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question