Solved

Default argument in function causes error

Posted on 2003-11-24
3
238 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the help!  The file got included more than once and I forgot the define...
Greetz
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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.

771 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

9 Experts available now in Live!

Get 1:1 Help Now