Question

This builds fine as a parameter to a function declaration on x64 VS100 (MSVC++ 2010) but fails on RHEL5 (gcc 4.1.2):

const std::vector<std::pair<std::string, std::string> >& = std::vector<std::pair<std::string, std::string> >()

The whole function since some have asked is (with said parameter being the 3rd):

    bool func(const std::string&, const std::vector<int>&, const std::vector<std::pair<std::string, std::string> >& = 
        std::vector<std::pair<std::string, std::string> >(), const std::vector<std::string>& = std::vector<std::string>(), 
        const std::vector<std::string>& = std::vector<std::string>(), const std::vector<double>& = std::vector<double>(), 
        const std::vector<double>& = std::vector<double>(), const std::vector<double>& = std::vector<double>(), 
        const std::vector<double>& = std::vector<double>(), const std::vector<double>& = std::vector<double>(), 
        const std::string& = "", const std::string& = "", const std::string& = "") const;

The error I got on RHEL5 gcc-4.1.2 is:

line #: error: expected ',' or '...' before '>' token
line #: error: wrong number of template arguments (1, should be 2)
line #: error: template argument 1 is invalid
line #: error: template argument 2 is invalid

Note that this compiles fine on both platforms with 3rd parameter replaced by:

std::vector<std::string>& = std::vector<std::string>()

My current workaround is to use the latter form and change my implementation a bit to account for it, and this does the job currently. But any ideas why the original usage is failing to build on RHEL5 gcc-4.1.2 and what would be correct usage is very appreciated. Thank you.

Était-ce utile?

La solution

The code is correct. What you have is most probably a bug in GCC 4.1. Non-ancient versions of GCC compile this code just fine.

Other than that, make sure you actually include the headers you need:

#include <vector>
#include <string>
#include <utility> // for std::pair

Autres conseils

My guess is that you haven't included <vector>.

On one compiler, it is indirectly included by some other header, so the declaration compiles.

On the other, it has only seen a declaration of std::vector, specifying two template parameters, and not the full definition, specifying the default value for the second; so the compiler complains that there should be a second one.

Make sure you're including that, and also <string> and <utility> for std::string and std::pair.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top