Solved

Default argument in function causes error

Posted on 2003-11-24
3
244 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
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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…
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…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

786 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