I am getting error C2512 when I am calling the constructor of a class from another class's constructor. I am using template instances at the bottom of the file, so that I wouldn't have to implement the member functions in the header. Normally, this is caused by not having a default constructor, but I do.
vec.h
template <class TYPE> class vec {
struct vecimp;
vecimp *imp;
public:
vec() { }
vec(const TYPE *, size_t);
~vec();
};
vec.cpp
#include "vec.h"
template <class TYPE> struct vec<TYPE>::vecimp {
TYPE *arr;
size_t n;
vecimp(const TYPE *arr, size_t n)
{
this->arr = (TYPE *) malloc(n * sizeof(TYPE));
this->n = n;
}
~vecimp()
{
free(this->arr);
this->arr = NULL;
}
};
template <class TYPE> vec<TYPE>::vec(const TYPE *arr, size_t n)
{
this->imp =
new vecimp
<TYPE> // C2512 occurs here
(arr, n);
}
// member function implementations, dtor, etc
template class vec<int>;
Here is the error message text
'vec::vecimp': no appropriate default constructor available
So I tried to add a default constructor to my vecimp
class, but then it gave me the compiler error C2275, at the same place as now.