尝试编译此代码时:
#include <iostream>
#include <vector>
using namespace std;
class Test {
int a;
public:
Test(int pa) : a(pa) { }
void print() {
std::cout << a << std::endl;
}
};
int main() {
Test t(31415);
t.print();
vector<Test &> vet;
vet.push_back(&t);
return 0;
}
gcc 4.4.5-8 报告各种错误,首先是:
In file included from /usr/include/c++/4.4/i486-linux-gnu/bits/c++allocator.h:34,
from /usr/include/c++/4.4/bits/allocator.h:48,
from /usr/include/c++/4.4/string:43,
from /usr/include/c++/4.4/bits/locale_classes.h:42,
from /usr/include/c++/4.4/bits/ios_base.h:43,
from /usr/include/c++/4.4/ios:43,
from /usr/include/c++/4.4/ostream:40,
from /usr/include/c++/4.4/iostream:40,
from references.cpp:1:
/usr/include/c++/4.4/ext/new_allocator.h: In instantiation of ‘__gnu_cxx::new_allocator<Test&>’:
/usr/include/c++/4.4/bits/allocator.h:87: instantiated from ‘std::allocator<Test&>’
/usr/include/c++/4.4/bits/stl_vector.h:71: instantiated from ‘std::_Vector_base<Test&, std::allocator<Test&> >’
/usr/include/c++/4.4/bits/stl_vector.h:171: instantiated from ‘std::vector<Test&, std::allocator<Test&> >’
references.cpp:22: instantiated from here
...
错误在哪里?