小编Roh*_*anK的帖子

尝试引用已删除函数的唯一指针

您好,我正在尝试使用指针并学习C++. 下面是我的代码,我已经注释了 main 函数中的代码行。调试问题但是,我无法这样做。我缺少什么?我的move()方法不对吗insertNode()?我得到的错误位于代码下方:

#include<memory>
#include<iostream>

struct node{
    int data;
    std::unique_ptr<node> next;
};


void print(std::unique_ptr<node>head){
        while (head)
            std::cout << head->data<<std::endl;
    }


std::unique_ptr<node> insertNode(std::unique_ptr<node>head, int value){
        node newNode;
        newNode.data = value;
        //head is empty
        if (!head){
            return std::make_unique<node>(newNode);
        }
        else{
            //head points to an existing list
            newNode.next = move(head->next);
            return std::make_unique<node>(newNode);
        }
    }



auto main() -> int
{
    //std::unique_ptr<node>head;
    //for (int i = 1; i < 10; i++){
    //  //head = insertNode(head, i);
    //}
} …
Run Code Online (Sandbox Code Playgroud)

c++ pointers unique-ptr

1
推荐指数
1
解决办法
1万
查看次数

Bash脚本未运行

我正在尝试学习bash脚本,并且正在使用Ubuntu Linux。我编写了一个简单的Bash文件来计算当前目录中的文件数。我已经在文件中编写了以下脚本:

#! /bin/bash

ls -1 | wc -l  
Run Code Online (Sandbox Code Playgroud)

并以名称保存文件countFile

但是,当我尝试使用脚本执行脚本时却./countFile无法执行。它显示以下错误:

bash: ./countFile: Permission denied  
Run Code Online (Sandbox Code Playgroud)

countFile位于我的主目录中,所以为什么我没有这个权限。我是在做错事还是错过了重要的事情?而且,ls -1 | wc -l从终端运行该命令时,它会为我提供正确的输出。
那么如何运行countFile脚本?

linux bash shell terminal ubuntu

0
推荐指数
1
解决办法
5436
查看次数

标签 统计

bash ×1

c++ ×1

linux ×1

pointers ×1

shell ×1

terminal ×1

ubuntu ×1

unique-ptr ×1