Could anyone help me with the following problem?
There is a simple code:
#include <vector>
struct A {
std::vector<int> vec;
};
void func (A &&a = {}) {}
int main()
{
func();
return 0;
}
When I try to compile it by gcc 5.4.0 I get the error:
undefined reference to `std::vector<int, std::allocator<int> >::vector()'
Amazingly, but clang compiles it well. Also if to modify the code a little bit it is compiled without any problems:
#include <vector>
struct A {
std::vector<int> vec;
};
void func (A &&a) {}
int main()
{
func({});
return 0;
}
I really cann't understand what's wrong with the first code.
main': main.cpp:(.text+0x1b): undefined reference to
std::vector<int, std::allocator<int> >::vector()' collect2: error: ld returned 1 exit status – Aggravationtemplate
and hence fullyinline
. The compiler should have generated that, rather than asking the linker to load it. – Leshiavector
withlist
(or any other templated container I suppose). – Leshia