I have a small snipped of code, which just produces a function to get the current directory for either Windows or Linux platform:

```
#include <stdio.h>  /* defines FILENAME_MAX */
#include <string>
#ifdef WINDOWS
    #include <direct.h>
    #define GetCurrentDir _getcwd
#else
    #include <unistd.h>
    #define GetCurrentDir getcwd
 #endif

    std::string getcwd(){
    char mCurrentPath[FILENAME_MAX];
    GetCurrentDir(mCurrentPath, sizeof(mCurrentPath));
    return *(new std::string (mCurrentPath));

    }

```

This is all great and working; however, I'd like to make the `getcwd()` function inside the namespace, `fUtils`, hence I did this: 

```
#include <stdio.h>  /* defines FILENAME_MAX */
#include <string>
#ifdef WINDOWS
    #include <direct.h>
    #define GetCurrentDir _getcwd
#else
    #include <unistd.h>
    #define GetCurrentDir getcwd
 #endif

namespace fUtils{
    std::string getcwd(){
    char mCurrentPath[FILENAME_MAX];
    GetCurrentDir(mCurrentPath, sizeof(mCurrentPath));
    return *(new std::string (mCurrentPath));

    }
}

```

But this gives an error in `VSCode` which says: 

> 
> `no matching function for call to 'getcwd'`
> 
> 
> 

What mistake am I making in this? If this isn't how I put the function to the namespace `fUtils`, then how should I put it into the namespace?
['https://Stackoverflow.com/questions/62152528', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9007093/']
Your `fUtils::getcwd()` function is attempting to call *itself* when the `GetCurrentDir` macro is evaluated (to `getcwd`), and this results in a function that expects no argument but is being given two arguments.

To resolve this, add the global namespace operator (`::`) in the definitions for `GetCurrentDir`, as follows:

```cpp
#ifdef WINDOWS
    #include <direct.h>
    #define GetCurrentDir ::_getcwd
#else
    #include <unistd.h>
    #define GetCurrentDir ::getcwd
#endif

```

Then, in your function body, it is clear to the compiler that your aren't looking for a 'recursive' (and invalid) call.
Use of macros in such context is invitation to problems in future.

Just wrap those functions with own API and all problems will be resolved.

Header file:

```cpp
#include <string>

namepsace fUtils {
std::string getcwd();
}

```

Then you can have platform specific cpp files, Windows:

```cpp
namepsace fUtils {
std::string getcwd() {
    char mCurrentPath[FILENAME_MAX];
    ::_getcwd(mCurrentPath, sizeof(mCurrentPath));
    return {mCurrentPath};
}
}

```

Mac version is obvious.

You also can use this macros inside single cpp file and this way contain them there if you do not what to do larger clean up.

Side notes:
-----------

* there is `boost::filesystem` which has such api also use of `boost::filesystem::path` is quite handy
* C++17 introduces `std::filesystem`, but it is not well supported yet (for example MacOS)
* if you wrap this functionality in classes you will open your way for better testing (mocks).