Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Default argument in function causes error

Posted on 2003-11-24
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

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 200 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

Industry Leaders: 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!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

721 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