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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Title # Comments Views Activity
maze travler 6 73
Quicksort a dynamic deque 33 83
Eclipse IDE - Cannot copy/paste from console output 8 388
Embarcadero C++ Builder XE10.1 Berlin red arrow Indicator 2 100
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

751 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