Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/143.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;“与Clion一起”;预期为`、';或`……';在'之前&&';代币;_C++_Oop_Compiler Errors_C++17_Clion - Fatal编程技术网

C++ C++;“与Clion一起”;预期为`、';或`……';在'之前&&';代币;

C++ C++;“与Clion一起”;预期为`、';或`……';在'之前&&';代币;,c++,oop,compiler-errors,c++17,clion,C++,Oop,Compiler Errors,C++17,Clion,嗨,伙计们,我无法解决我在代码中发现的以下错误: IDE指示的错误指向移动构造函数。IDE不向我报告错误,当我编译时,它会给我错误 Scanning dependencies of target Lab_01 [ 33%] Building CXX object CMakeFiles/Lab_01.dir/main.cpp.obj In file included from C:\Users\alex\CLionProjects\LabPDS\Lab_01\main.cpp:2: C:\U

嗨,伙计们,我无法解决我在代码中发现的以下错误: IDE指示的错误指向移动构造函数。IDE不向我报告错误,当我编译时,它会给我错误

Scanning dependencies of target Lab_01

[ 33%] Building CXX object CMakeFiles/Lab_01.dir/main.cpp.obj

In file included from C:\Users\alex\CLionProjects\LabPDS\Lab_01\main.cpp:2:

C:\Users\alex\CLionProjects\LabPDS\Lab_01\Message.h:21: error: expected `,' or `...' before '&&' token

C:\Users\alex\CLionProjects\LabPDS\Lab_01\Message.h:21: error: invalid constructor; you probably meant `Message (const Message&)'

C:\Users\alex\CLionProjects\LabPDS\Lab_01\Message.h:23: error: **expected `,' or `...' before '&&' token**

mingw32-make.exe[3]: *** [CMakeFiles/Lab_01.dir/main.cpp.obj] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/Lab_01.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/Lab_01.dir/rule] Error 2
mingw32-make.exe: *** [Lab_01] Error 2
有人能帮我吗

第2行中的my class main.cpp在class Message.h中查找错误

#include <iostream>
#include "Message.h"

int main() {
    Message m1(10);
    std::cout << m1 << std::endl;
    return 0;
}
// Created by Alexandro Vassallo on 10/04/2020.

#ifndef LAB_01_MESSAGE_H
#define LAB_01_MESSAGE_H


class Message {

    long id;
    char* data;
    int size;
    static long sId;

    char* mkMessage(int n);

public:
    Message();                                      //Costruttore di Default
    Message(int n);                                 //Costruttore con un solo parametro
    ~Message();                                     //Distruttore
    Message(const Message& source);                 //Costruttore di copia
    Message(Message&& source);                      //Costruttore di movimento
    Message& operator=(const Message& source);      //Operatore di assegnazione
    Message& operator=(Message&& source);           //Operatore di assegnazione di movimento

    long getId() const;

    void setId(long id);

    char *getData() const;

    void setData(char *data);

    int getSize() const;

    void setSize(int size);

    static long getSId();

    static void setSId(long sId);
};

std::ostream& operator<<(std::ostream& out, const Message& m);


#endif //LAB_01_MESSAGE_H
#包括
#包括“Message.h”
int main(){
信息m1(10);
std::cout data=新字符[大小];
memcpy(这个->数据,源,数据,大小);
}
消息::消息(消息和源){
此->id=source.id;
此->大小=source.size;
此->数据=source.data;
source.id=-1;
source.size=0;
source.data=nullptr;
}
消息和消息::运算符=(常量消息和源){
if(此!=&source){
删除[]此->数据;
此->数据=空PTR;
此->大小=source.size;
此->数据=新字符[大小];
memcpy(这个->数据,源,数据,大小);
}
归还*这个;
}
消息和消息::运算符=(消息和源){
if(此!=&source){
删除[]此->数据;
此->大小=source.size;
此->数据=source.data;
source.data=nullptr;
}
归还*这个;
}
长消息::getId()常量{
返回id;
}
无效消息::setId(长id){
Message::id=id;
}
char*消息::getData()常量{
返回数据;
}
无效消息::设置数据(字符*数据){
消息::数据=数据;
}
int Message::getSize()常量{
返回大小;
}
无效消息::设置大小(整数大小){
消息::大小=大小;
}
长消息::getSId(){
返回sId;
}
无效消息::设置ID(长sId){
Message::sId=sId;
}
字符*消息::mkMessage(int n){
std::string元音=“aeiou”;
std::string consolants=“bcdfghlmnqrstvz”;
char*m=新字符[n+1];
对于(int i=0;istd::ostream&operator确保您使用的是C++11或更高版本。移动语义不受旧版本的支持。

Cmake文件:cMaMyMimuluMuthEngress(版本3.15)项目(Laby01)集(CMACHYCXXY标准17)Addia可执行文件(Labv01 Maun.CPP Masaq.CPP消息h),比使用C++更有效17@AlexandroVassallo添加
set(CMAKE\u VERBOSE\u MAKEFILE on)
访问您的CMake文件,查看它用于验证是否确实在使用c++17的实际命令。如果不是,您将得到如下所示的确切错误@TEDLYNMO谢谢,您解决了问题,我用c++11/17安装了最新版本的Mingw。太好了!不过,这都是安德斯干的。我刚刚听到了他/她的答案。很高兴你已经解决了:)将
set(CMAKE\u VERBOSE\u MAKEFILE on)
添加到
CMakeLists.txt
中,并将编译时得到的输出包含在问题中。
// Created by Alexandro Vassallo on 10/04/2020.

#include <string>
#include <iostream>
#include "Message.h"
long Message::sId = 0;

Message::Message(): id(-1), size(0){
    this->data = mkMessage(0);
}

Message::Message(int n): size(n) {
    this->id= sId++;
    this->data = mkMessage(n);
}

Message::~Message() {
    delete[] data;
}

Message::Message(const Message &source):id(source.id), size(source.size) {
    this->data = new char[size];
    memcpy(this->data,source.data,size);
}

Message::Message(Message &&source) {
    this->id = source.id;
    this->size = source.size;
    this->data = source.data;
    source.id = -1;
    source.size = 0;
    source.data = nullptr;
}

Message &Message::operator=(const Message &source) {

    if(this != &source){
        delete[] this->data;
        this->data = nullptr;
        this->size = source.size;
        this->data = new char[size];
        memcpy(this->data, source.data,size);
    }

    return *this;
}

Message &Message::operator=(Message &&source) {

    if(this != &source){
        delete[] this->data;
        this->size = source.size;
        this->data = source.data;
        source.data = nullptr;
    }

    return *this;
}


long Message::getId() const {
    return id;
}

void Message::setId(long id) {
    Message::id = id;
}

char *Message::getData() const {
    return data;
}

void Message::setData(char *data) {
    Message::data = data;
}

int Message::getSize() const {
    return size;
}

void Message::setSize(int size) {
    Message::size = size;
}

long Message::getSId() {
    return sId;
}

void Message::setSId(long sId) {
    Message::sId = sId;
}

char* Message::mkMessage(int n) {
    std::string vowels ="aeiou";
    std::string consolants = "bcdfghlmnqrstvz";

    char* m = new char[n+1];
    for(int i = 0 ; i < n ; i++){
        m[i] = i%2 ? vowels[rand()%vowels.size()]:consolants[rand()%consolants.size()];
    }
    m[n] = 0;
    return m;
}

std::ostream& operator<<(std::ostream& out, const Message& m){
    out << m.getId() << m.getSize() << m.getData();
    return out;
}