开发者社区> 问答> 正文

用*&当参数时报错,去掉&就可以

void InitList(SqList &L)//初始化列表其中&L为引用型指针
{
L = (SqList*)malloc(sizeof(SqList));
L->length = 0;
}

image.png 这里加&报错

展开
收起
海边一只船 2020-05-27 15:57:24 631 0
1 条回答
写回答
取消 提交回答
  • 怎么报的错,本地试了一下,无问题。

    #include <iostream>
    #include <stdlib.h> 
    
    using namespace std;
    
    struct SqList
    {
        int length;
    };
    
    void InitList(SqList *&L)//初始化列表其中&L为引用型指针
    {
        L = (SqList*)malloc(sizeof(SqList));
        L->length = 12;
    }
    
    int main() {
        SqList *L;
        InitList(L);
        cout << L->length << endl;
        return 0;
    }
    
    

    g++ hello.cpp -o hello 编译

    2020-05-27 17:52:14
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载