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

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. RMAN:简单的duplicate创建新数据库 for 12c+

    构建参数文件 *.db_name='test2' ##### 需要注意的地方,和rman的duplicate目标库一致 *.compatible='18.0.0' ##### 关键的地方,每个版本的模 ...

  2. C#文件操作工具类

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

  3. SpringBoot------使用Fastjson解析Json数据

    方法一: 1.在pom.xml文件下添加依赖包 <dependency> <groupId>com.alibaba</groupId> <artifactId ...

  4. android应用开发-从设计到实现 3-4 静态原型的状态栏

    静态原型的状态栏 状态栏Symbol 状态栏似乎非常复杂,有wifi信号.手机信号.时间.电量等信息,幸好Sketch原生就自带的现成组件,你能够直接拿过来就用了.当然.你也能够自己一个一个去画,只是 ...

  5. hdu 2348 Turn the corner(三分&amp;&amp;几何)(中等)

    Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. logback -- 配置详解 -- 四 -- <filter>

    附: logback.xml实例 logback -- 配置详解 -- 一 -- <configuration>及子节点 logback -- 配置详解 -- 二 -- <appen ...

  7. javascript 以“年-月-日 时:分:秒”格式显示当前时间

    运行代码 /** * Created by shgbit on 2015/1/9. *js代码 */ function showNow(){ var t=new Date();    var mont ...

  8. javascript 显示一定范围内的素数(质数)

    素数又称质数,是大于1的自然数,并且只有1和它本身两个因数. 具体实现代码如下: 运行代码 <!DOCTYPE HTML> <html> <head lang=" ...

  9. 【GIS】WGS84与Web墨卡托理解(转)

    坐标系 · WGS84,地理坐标系,单位度,在三维上可以很好的展示全球的数据,但在二维上显示时在高纬度地区变形较大,另由于WGS84坐标系与CGCS2000坐标系差异很小,所以WGS84坐标系在Web ...

  10. 【Java-Web】初始化加载Serlvet工程后-HttpServlet报错

    1.Tomcat配置 2.Java Build Path