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

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. ul li列表元素浮动导致border没有底边解决办法

    如图,当ul li,li元素浮动,并且ul元素也overflow:hidden清除浮动的时候,给li元素加了border,但是不显示底边,这时候要看是不是没有给li元素加高,因为加了border之后默 ...

  2. Nine-patch

    http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch   This NinePatch defi ...

  3. tomcat和nginx的使用

    1.下载tomcat,配置conf/server.xml,在Host节点下添加Context节点,指定程序目录: <Context path="/ol" docBase=&q ...

  4. linux环境中安装ftp服务

    需求说明: 今天项目中有一个新的需求,需要在linux环境中搭建一个ftp服务,在此记录下. 操作过程: 1.通过yum的方式安装ftp服务对应的软件包 [root@testvm01 ~]# yum ...

  5. linux sed在某些字符串的下一行插入内容?sed在下一行插入?

    需求描述: 今天在配置nrpe的时候,使用到了在搜索到某些字符串之后,然后在字符串的下一行进行插入字符串 在此记录下如何实现. 即通过sed的a命令实现内容的追加. 操作过程: 1.查看原文件中的内容 ...

  6. Batch Normalization 学习笔记

    原文:http://blog.csdn.net/happynear/article/details/44238541 今年过年之前,MSRA和Google相继在ImagenNet图像识别数据集上报告他 ...

  7. feed流拉取,读扩散,究竟是啥?

    from:https://mp.weixin.qq.com/s?__biz=MjM5ODYxMDA5OQ==&mid=2651961214&idx=1&sn=5e80ad6f2 ...

  8. SpringBoot------文件上传

    1.pom.xml引入依赖配置 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http ...

  9. linux 端口占用情况

    1,查看8010端口是否被占用 [root@cloud ~]# netstat -an|grep 8010 tcp 0 0 0.0.0.0:8010 0.0.0.0:* LISTEN 2,查看8010 ...

  10. Jsoup(一)-- HelloWorld

    1.简介 jsoup 是一款Java 的HTML解析器,可直接解析某个URL地址.HTML文本内容.它提供了一套非常省力的API,可通过DOM,CSS以及类似于jQuery的操作方法来取出和操作数据. ...