I defined a struct and initialized it, resulting in a compile error.
No appropriate default constructor available
The code is as follows:
struct matrixxvect_func{thrust::host_vector<float>& matrix;thrust::host_vector<float>& vector ; int Matrix_rownum;int matrix_colnum;__host__ __device__float operator () (const int& idx) const{float t=0;for (int Col=0;col<matrix_colnum;++col) {t+=matrix[idx*matrix_colnum+col]* vector[col];} return t;}; int main (int argc, char* argv[]) { matrixxvect_func fn; return 0; }
That I don't have a constructor? But I'm a structural body, eh! What constructor does the struct need?
Originally I this structure has the object reference:thrust::host_vector<float>& matrix;
This reference needs to be initialized, so the compiler prompts me to have a constructor.
Solution 1: Changing the reference to a pointer does not need to be initialized.
Solution 2: Remove the reference, just declare a variable, but this assignment is the copy assignment? Seems to have violated the purpose of the quote ~
C + + Error:no appropriate default constructor available