default parameters

Discussion in 'C++' started by Victor Bazarov, Aug 30, 2004.

  1. Ekim wrote:
    > hy,


    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
     
    Victor Bazarov, Aug 30, 2004
    #1
    1. Advertising

  2. Victor Bazarov

    Ekim Guest

    "Victor Bazarov" <> wrote in message
    news:G5IYc.555$09.us.to.verio.net...
    > Ekim wrote:
    > > hy,

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


    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!
     
    Ekim, Aug 30, 2004
    #2
    1. Advertising

  3. Victor Bazarov

    Ekim Guest

    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
     
    Ekim, Aug 31, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonck van der Kogel
    Replies:
    2
    Views:
    1,003
    Jonck van der Kogel
    May 27, 2004
  2. Jason
    Replies:
    2
    Views:
    534
    Jonathan Mcdougall
    May 13, 2006
  3. desktop
    Replies:
    2
    Views:
    475
    Victor Bazarov
    Jun 6, 2007
  4. kito
    Replies:
    2
    Views:
    434
  5. Florian Loitsch
    Replies:
    11
    Views:
    258
    Michael Winter
    Mar 15, 2005
Loading...

Share This Page