Cannot initialize a variable of type 'Stu *' with an rvalue of type 'void *'
code:
将
Stu* pStu = malloc(sizeof(Stu));
改为
Stu* pStu = (Stu*)malloc(sizeof(Stu));
code
#include <stdio.h> #include <stdlib.h>typedef struct {int a;int b; }Stu;Stu* getStu(int x, int y) {Stu* pStu = (Stu*)malloc(sizeof(Stu));pStu->a = x;pStu->b = y;return pStu; }int main() {int x = 2, y = 3;Stu *pStu = getStu(x, y);printf("%d %d\n", pStu->a, pStu->b);free(pStu);return 0; }
输出
2 3 Program ended with exit code: 0
https://blog.csdn.net/weixin_34221332/article/details/86981433
转载于:https://www.cnblogs.com/sea-stream/p/11129947.html
Cannot initialize a variable of type 'Stu *' with an rvalue of type 'void *'相关推荐
- C++ stack pop()返回值 error: cannot initialize a variable of type ‘int‘ with an rvalue of type ‘void‘
LeetCode一道链表倒置题目 struct ListNode {int val;ListNode *next;ListNode(int x) : val(x), next(NULL) {} };c ...
- QT之error: cannot bind non-const lvalue reference of type ‘CBaowen’ to an rvalue of type ‘CBaowen
问题描述:QT中自己编写了一个结构体变量CBaowen,报文中含有函数重载部分(如下所示), 之后定义一个队列变量 QQueue<CBaowen> queue; 当给队列变量赋值时que ...
- cannot bind non-const lvalue reference of type ‘xxx‘ to an rvalue of type ‘xxx‘
文章目录 报错代码 报错 原因 解决方案 报错代码 #include<iostream> using namespace std; class Complex{private:double ...
- C++之error: cannot bind non-const lvalue reference of type ‘myString’ to an rvalue of type ‘myString
先看代码(不想看代码可以直接看代码后的问题描述) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ...
- C++之invalid initialization of non-const reference of type ‘int’ from an rvalue of type ‘int’
1.看代码 2.编译结果 3.分析和解决 就拿f(a + b)来说,a+b的值会存在一个临时变量中,当把这个临时变量传给f时,由于f的声明中,参数是int&,不是常量引用,因为c++编译器的一 ...
- cannot bind non-const lvalue reference of type ‘***‘ to an rvalue of type ‘***‘解决方法
在写C++作业的时候,我发现使用 #include <iostream> class complex{public:int real;int imaginary;public:comple ...
- 【C++---const引用】数组进行指针引用传递给函数error: non-const lvalue reference of type ‘int*‘ to an rvalue
目录 原因 类型转换 手动转换 自动转换 关于临时量 关于常量引用(const的引用) const引用的对象不是不能被修改了吗,这里为什么被修改了? 不是说是const引用吗?为什么又变成了引用所绑定 ...
- Format specifies type 'id' but the argument has type 'NSError *__autoreleasing *
我想打印error,但是出现了标题中的错误,代码如下: -(id)yobee_responseObjectForResponse:(NSURLResponse *)response data:(NSD ...
- R语言使用plot函数和lines函数可视化线图(line plot)时、图之间的主要区别是由选项type产生的、type参数常用参数说明、不同type生成的可视化图像对比
R语言使用plot函数和lines函数可视化线图(line plot)时.图之间的主要区别是由选项type产生的.type参数常用参数说明.不同type生成的可视化图像对比 目录
最新文章
- win运行pycharm找不到要加载的model.pkl文件是workingspace设置路径与文件路径位置不对应
- php中单引号和双引号的区别,哪个速度更快?为什么?
- 举例说明html语言的结构,HTML语言的结构
- MediaSource 缓存
- Android的数据存储
- 坐标上升算法(Coordinate Ascent)及C++编程实现
- 数据结构 递归讲解
- reactor设计模式 1
- 常见字符编码 java
- Python框架篇之Django(Template模版:标签tag、自定义filter、extend模板继承)
- XP框架的另外选择→太极
- YOLOv5数据集标注工具
- Verilog HDL实现智能药盒
- pip下载太慢?聪明人都这样
- 放不下的原理_通俗易懂,几张图看懂大数据存储和计算原理
- GKCTF2020 逆向部分题的复现
- 2021下半年中小学教资考试教育知识与能力试题(中学)——主观题
- 2017年的端午节祝福语
- vue获取一个月有多少天
- PC企业微信hook接口,通过查询添加外部联系人教程