default parameters

V

Victor Bazarov

Ekim said:

hy yourself.
I've got a question according default parameters of functions that are
accessed from different files:

---- logging.h ----
void LogTrace(const char* errorLocation, const char* errorInfo = "-");
// define default-param
---- end of logging.h ---


---- logging.cpp ----

#include "Logging.h"

void LogTrace(const char* errorLocation, const char* errorInfo)
{ // define function-body
// do something
}
---- end of logging.cpp ---


and using that function from let's say 2 files in the same project like this
:
--- file1.cpp ---
#include "Logging.h"

and within any function call:
LogTrace("don't use default param", "test"); // call
function without default parameter
LogTrace("use default param"); //
call function with default parameter

--- end of file1.cpp ---


If I call this function as described above in just one .cpp-file, everything
works fine. But as soon as I want to call this function from a second file
within the same project, I get the following error-message:
"LogTrace": redefinition of default parameter: parameter 2

Can someone please tell me what I did wrong?


Could it be you somehow include the "Logging.h" file twice? Put some
double include guards in that file.

Victor
 
E

Ekim

Victor Bazarov said:
hy yourself.



Could it be you somehow include the "Logging.h" file twice? Put some
double include guards in that file.

Victor

yeah you're absolutely right again,
now that you mention it it's somehow clear to me - I should have made
something like #ifndef...#define...

thx once more for immediate help,
ekim!
 
E

Ekim

hy,
I've got a question according default parameters of functions that are
accessed from different files:

---- logging.h ----
void LogTrace(const char* errorLocation, const char* errorInfo = "-");
// define default-param
---- end of logging.h ---


---- logging.cpp ----

#include "Logging.h"

void LogTrace(const char* errorLocation, const char* errorInfo)
{ // define function-body
// do something
}
---- end of logging.cpp ---


and using that function from let's say 2 files in the same project like this
:
--- file1.cpp ---
#include "Logging.h"

and within any function call:
LogTrace("don't use default param", "test"); // call
function without default parameter
LogTrace("use default param"); //
call function with default parameter

--- end of file1.cpp ---


If I call this function as described above in just one .cpp-file, everything
works fine. But as soon as I want to call this function from a second file
within the same project, I get the following error-message:
"LogTrace": redefinition of default parameter: parameter 2

Can someone please tell me what I did wrong?

I appreciate any help,
ekim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top