std::vector resize and Class copy constructor
Code:
#include <vector>
class T1
{
public:
T1(int* a) : m_pInt(a) {}
T1(T1& a) : m_pInt(a.m_pInt) {}
private:
int* m_pInt;
};
int main(void)
{
std::vector<T1> test;
T1 t(NULL);
test.resize(10,t);
return 0;
}
I see no reason why this shouldn't compile. Of course, when the compiler and I are in disagreement, the compiler wins. Here's the error I get:
Code:
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\vector(810) :
error C2558: class 'T1' : no copy constructor available or copy constructor
is declared 'explicit'
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\vector(809) :
while compiling class-template member function
'void std::vector<_Ty>::_Insert_n(std::vector<_Ty>::iterator,
std::vector<_Ty>::size_type,const _Ty &)'
with
[
_Ty=T1
]
main.cpp(20) : see reference to class template instantiation 'std::vector<_Ty>'
being compiled
with
[
_Ty=T1
]
As you can see, I'm using .Net 2003.