Background
Class Foo
has user-declared constructor and thus no implicitly-declared default constructor:
struct Foo {
Foo(...) {...}
};
It is then used in the std::vector
of std::pair
as follows:
std::vector<std::pair<std::string, Foo> >
Usage
Attempting to push back in the vector:
std::vector<std::pair<std::string, Foo> > v;
v.push_back(std::make_pair(std::string("some string"), Foo(...)));
Compilation error (VS2008 SP1)
The following error C2512:
'Foo' : no appropriate default constructor available
...\Microsoft Visual Studio 9.0\VC\include\utility(43):
while compiling class template member function 'std::pair<_Ty1,_Ty2>::pair(void)'
Notes
std::vector
documentation says it should accept copy-assignable and copy-constructible objects:T must meet the requirements of CopyAssignable and CopyConstructible (until C++11).
The code compiles just fine with gcc and VS2008 (pre SP1).
Question
What is causing the error? Is there a bug in VS2008 SP1? If yes, what are the work-arounds?