我定义了一个结构体,然后初始化它,结果编译报错

no appropriate default constructor available

代码如下:

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;
}

说我没有构造函数?但是我这个是个结构体诶!结构体要什么构造函数?

原来我这个结构体中有对象的引用:thrust::host_vector<float>& matrix;

这个引用需要初始化,所以编译提示我要有构造函数。

解决方案1:把引用改成指针就不需要初始化了。

解决方案2:把引用去掉,直接就是声明一个变量,不过这么做赋值时就是拷贝赋值吧?似乎有违引用的初衷~

C++ Error: no appropriate default constructor available的更多相关文章

  1. Error:Error: Avoid non-default constructors in fragments: use a default constructor plus Fragment#setArguments(Bundle) instead [ValidFragment]

    原文博客链接:https://blog.csdn.net/chniccs/article/details/51258972 在创建fragment时,你可能在打包时碰到如下错误 Error:Error ...

  2. JSON parse error: default constructor not found. class java.time.YearMonth; nested exception is com.alibaba.fastjson.JSONException: default constructor not found. class java.time.YearMonth

    java8新出的YearMonth可以方便的用来表示某个月.我的项目中使用springmvc来接收YearMonth类型的数据时发现 x-www-from-urlencoded 格式的数据可以使用&q ...

  3. Avoid non-default constructors in fragments: use a default constructor plus Fragment#setArguments(Bundle) instead

    “Avoid non-default constructors in fragments: use a default constructor plus Fragment#setArguments(B ...

  4. 使用Spring报错:No default constructor found;

    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error ...

  5. Constructor Overloading in Java with examples 构造方法重载 Default constructor 默认构造器 缺省构造器 创建对象 类实例化

    Providing Constructors for Your Classes (The Java™ Tutorials > Learning the Java Language > Cl ...

  6. “Avoid non-default constructors in fragments: use a default constructor plus Fragment#setArguments(Bundle)instead”

    “Avoid non-default constructors in fragments: use a default constructor plus Fragment#setArguments(B ...

  7. Does compiler create default constructor when we write our own?

    In C++, compiler by default creates default constructor for every class. But, if we define our own c ...

  8. 错误:Implicit super constructor xx() is undefined for default constructor. Must define an explicit constructor

    错误:Implicit super constructor xx() is undefined for default constructor. Must define an explicit con ...

  9. C++编译器合成Default Constructor的4种情况

    笔记C++编译器为编译器需要合成Default Constructor的4种情况. 1,Class A内含Class B对象,Class A没有Default Constructor时会在编译时合成D ...

随机推荐

  1. HQS——Half Quadratic Splitting半二次方分裂

    变量分裂法 变量分裂法(Variable Splitting),解决目标函数是两个函数之和的优化问题. 1)其中g是n维向量到d维向量的一个映射. 变量分裂将上式变为: 问题(2)可能比(1)更容易或 ...

  2. dede栏目添加自定义字段方法

    1.首先要进mysql 数据库里添加字段,命名好!比如我下面添加了一个栏目备注字段,当然你字段可以自己新建,找到表dede_arctype(这个是栏目模型的数据库表,这里面我添加的是栏目备注字段cla ...

  3. Mongodb安全认证

    Mongodb安全认证在单实例和副本集两种情况下不太一样,单实例相对简单,只要在启动时加上 --auth参数即可,但副本集则需要keyfile. 一.单实例 1.启动服务(先不要加auth参数) 2. ...

  4. Linux Device Tree

     原创博文,转载请标明出处--周学伟 http://www.cnblogs.com/zxouxuewei/ 设备树使用手册 基本数据格式 设备树是一个包含节点和属性的简单树状结构.属性就是键-值对,而 ...

  5. iOS_UITextField 基本操作

    基本操作 UITextField *userNameTextField = [[UITextField alloc] init]; userNameTextField.frame = CGRectMa ...

  6. AngularJS------命令行

    如下:(‘$’符号不需要输入哦) $ ng build --发布项目

  7. 如何将数组中的后面m个数移动为前面m个数

    思路分析: 可以通过递归的方法实现调整: (1)将前n-m个元素的顺序颠倒. (2)将后面m个元素的顺序颠倒. (3)将n个元素的顺序全部颠倒. 通过以上3个步骤的执行,就可以把数组的元素颠倒. 代码 ...

  8. 5 -- Hibernate的基本用法 --3 Hibernate的体系结构

    ⊙ SessionFactory : 这是Hibernate的关键对象,它是单个数据库映射关系经过编译后的内存镜像,也是线程安全的.它是生成Session的工厂,本身需要依赖于ConnectionPr ...

  9. 为什么GPL是更好的开源许可证?

    1. 让我从一件新闻讲起. 2009年,计算机业界发生了一件大事:甲骨文公司以74亿美元收购SUN公司. 消息宣布后,有一个人坚决反对这笔交易.他叫Michael Widenius,是数据库软件MyS ...

  10. 02python程序和用户交互

    在写程序时,使用python的内置函数来获取用户输入的值. >>> name = input("Input your name:")Input your name ...