Default argument in function causes error

Posted on 2003-11-24
Last Modified: 2010-08-05

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.

String removeLeadingZeros(String stInput, bool removeLastZero=true);

String removeLeadingZeros(String stInput, bool removeLastZero)
        if(stInput.Length()<1) return "";
        bool removedAZero = false;
                        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.
Question by:cleaverX

Expert Comment

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

Accepted Solution

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


Author Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

912 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now