c++windowsmacosstd

Error on std::pair when compiling for mac / linux


I have a problem when compiling my code under Mac OS. This function declaration in my header file apparently causes some errors (it does work fine under Windows, though):

#include <string>
#include <vector>
#include <map>

#ifdef WIN32
    #include <windows.h>
#endif

[...]

    int setProcessEnvironment(
        const wchar_t * procName,
        const wchar_t * appName = NULL,
        const wchar_t * workingDir = NULL,
        const wchar_t * cmdArgs = NULL,
        const std::vector< std::pair<const wchar_t *, int> > &systemEnvVars = std::vector< std::pair<const wchar_t *, int> >()
    );

It looks like the compiler doesn't like the input for my pair - maybe I am missing some includes or what is the problem here?

I also don't fully understand the last line of this error message as my function description actually looks very different to the one in this error...

I am starting to think it may have to do with the default initialization, but what is the difference between the Mac and Windows compiler here?

26: error: expected ‘,’ or ‘...’ before ‘>’ token
26: error: wrong number of template arguments (1, should be 2)
/usr/include/c++/4.2.1/bits/stl_pair.h:68: error: provided for ‘template<class _T1, class _T2> struct std::pair’
26: error: template argument 1 is invalid
26: error: template argument 2 is invalid
26: error: default argument missing for parameter 6 of ‘int SysProcManager::setProcessEnvironment(const wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*, const std::vector<std::pair<const wchar_t*, int>, std::allocator<std::pair<const wchar_t*, int> > >&, int)’
159: error: prototype for ‘int SysProcManager::setProcessEnvironment(const wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*, const std::vector<std::pair<const wchar_t*, int>, std::allocator<std::pair<const wchar_t*, int> > >&)’ does not match any in class ‘SysProcManager’
26: error: candidates are: int SysProcManager::setProcessEnvironment(const wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*, const std::vector<std::pair<const wchar_t*, int>, std::allocator<std::pair<const wchar_t*, int> > >&, int)
138: error:                 int SysProcManager::setProcessEnvironment(const wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*, const std::vector<const wchar_t*, std::allocator<const wchar_t*> >&)

Solution

  • this was pointed out by André Caron:

    Out of curiosity, can you typedef std::vector< std::pair > EnvironmentBlock; (change the name to your liking). Replace the two instances in your function declaration. See if that clears up any parsing errors.

    I am now declaring typedef std::vector< std::pair<const wchar_t*, int> > EnvironmentBlock; at the beginning and it does solve this problem on the Mac and it seems the compiler just can't deal with these nested types properly and screws things up - I did not see this problem on Linux or Windows, so maybe it's time to update my compiler (GCC 4.2).

    Thank you Andre!