C + + Error:no appropriate default constructor available

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.