Solved

Default argument in function causes error

Posted on 2003-11-24
3
260 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
[X]
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
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

617 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