“成员函数已定义或声明”-这是什么意思?

用户名

我正在编写一个程序,其中应列出一些任务,并按日期对它们进行排序,依此类推。

我做的最后一件事是添加“按日期排序”功能。在此之前,一切正常。如果我现在运行我的代码,则会收到以下错误消息(我收到此消息3次)

member function already defined or declared

我不明白,这是怎么回事。触发错误的代码如下所示:

static bool compareDates(entry e1, entry e2) { 
    string s1 = e1.date;
    string s2 = e2.date;

    int day_1 = atoi(s1.substr(0, 2).c_str());
    int month_1 = atoi(s1.substr(3, 2).c_str()); // dd.mm.yyyy
    int year_1 = atoi(s1.substr(6, 4).c_str());

    int day_2 = atoi(s2.substr(0, 2).c_str());
    int month_2 = atoi(s2.substr(3, 2).c_str());
    int year_2 = atoi(s2.substr(6, 4).c_str());

    if (year_1 > year_2) return true;
    else if (year_1 < year_2) return false;

    if (month_1 > month_2) return true;
    else if (month_1 < month_2) return false;

    if (day_1 > day_2) return true;
    else if (day_1 < day_2) return false;

    return true;
}

// ... some code in between ...

private: void sortList() { // in the class
    sort(john_lines.begin(), john_lines.end(), compareDates);
    sort(tomas_lines.begin(), tomas_lines.end(), compareDates);
    sort(bernd_lines.begin(), bernd_lines.end(), compareDates);
    sort(peter_lines.begin(), peter_lines.end(), compareDates);
}

我试图在没有其余代码的情况下运行此代码,并且该代码有效。有人知道我的应用程序有什么问题吗?这是我收到的错误消息:

Error 1 error C2535: 'void V2::MainWindow::sortList(void)' : member function already defined or declared
<path>\MainWindow.h 422 1 V2

Error 14 error C2535: 'void V2::MainWindow::sortList(void)' : member function already defined or declared
<path>\MainWindow.h 422 1 V2

Error 28 error C2535: 'void V2::MainWindow::sortList(void)' : member function already defined or declared
<path>\MainWindow.h 422 1 V2

这是我的代码:

#include <vector>
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <exception>
#include <algorithm>
#include <stdio.h>

using namespace std;

struct entry {
    string text;
    string date;
    bool finished;
};

vector< entry > john_lines;

bool compareDates(entry e1, entry e2) {
    string s1 = e1.date;
    string s2 = e2.date;

    int day_1 = atoi(s1.substr(0, 2).c_str());
    int month_1 = atoi(s1.substr(3, 2).c_str()); // dd.mm.yyyy
    int year_1 = atoi(s1.substr(6, 4).c_str());

    int day_2 = atoi(s2.substr(0, 2).c_str());
    int month_2 = atoi(s2.substr(3, 2).c_str());
    int year_2 = atoi(s2.substr(6, 4).c_str());

    if (year_1 > year_2) return true;
    else if (year_1 < year_2) return false;

    if (month_1 > month_2) return true;
    else if (month_1 < month_2) return false;

    if (day_1 > day_2) return true;
    else if (day_1 < day_2) return false;

    return true;
}

int main() {    
    entry e;

    e = { "clean the window", "12.08.2016", true };
    john_lines.push_back(e);
    e = { "tidy the room", "14.06.2012", false };
    john_lines.push_back(e);
    e = { "sort the papers", "16.08.2016", false };
    john_lines.push_back(e);
    e = { "writing the code for this application", "19.08.2018", false };
    john_lines.push_back(e);
    e = { "test period of this applicaition", "30.11.2020", false };
    john_lines.push_back(e);

    cout << "-------------------------------------------------------------------------------" << endl;
    cout << "- before:                                                                     -" << endl;
    cout << "-------------------------------------------------------------------------------" << endl;

    for(int i=0; i<john_lines.size(); i++) {
        e = john_lines.at(i);
        string finished = (e.finished) ? "(  done  ) " : "(not done) ";
        cout << finished << e.date << " - " << e.text << endl;
    }
    cout << endl << endl;

    sort(john_lines.begin(), john_lines.end(), compareDates);

    cout << "-------------------------------------------------------------------------------" << endl;
    cout << "- after:                                                                      -" << endl;
    cout << "-------------------------------------------------------------------------------" << endl;

    for(int i=0; i<john_lines.size(); i++) {
        e = john_lines.at(i);
        string finished = (e.finished) ? "(  done  ) " : "(not done) ";
        cout << finished << e.date << " - " << e.text << endl;
    }
}
附件

它在第83行中声明,并且可能在其他地方定义了它。

private: void sortList();

您已经在422行中重新定义了它

private: void sortList() {
        sort(john_lines.begin(), john_lines.end(), compareDates);
        sort(tomas_lines.begin(), tomas_lines.end(), compareDates);
        sort(bernd_lines.begin(), bernd_lines.end(), compareDates);
        sort(peter_lines.begin(), peter_lines.end(), compareDates);
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Typescript类型的匿名函数签名。这是什么意思?

来自分类Dev

构造函数后面的宏。这是什么意思?

来自分类Dev

这是什么意思:TypeError:dest.on不是函数

来自分类Dev

Friend函数类定义仅在非本地类定义中允许。这是什么意思?

来自分类Dev

Friend函数类定义仅在非本地类定义中允许。这是什么意思?

来自分类Dev

如果赋值/声明在C ++中意味着什么,这是什么意思

来自分类Dev

ngDialog.open未定义-这是什么意思?

来自分类Dev

单一构造函数代数数据类型:这是什么意思?

来自分类Dev

这是什么意思:找不到签名“ B”的函数“ A”的继承方法

来自分类Dev

静态内联函数比宏更受青睐。这是什么意思?

来自分类Dev

成员[H | T]是什么意思?

来自分类Dev

类型声明的“类”是什么意思?

来自分类Dev

该类声明是什么意思?

来自分类Dev

此属性声明是什么意思?

来自分类Dev

Haskell数据声明是什么意思

来自分类Dev

以下声明是什么意思?

来自分类Dev

该类声明是什么意思?

来自分类Dev

错误:在结构或联合中请求成员``下一个'',这是什么意思?

来自分类Dev

这个typedef定义是什么意思?

来自分类Dev

这个定义是什么意思?

来自分类Dev

这样的定义是什么意思?

来自分类Dev

BigDecimal的定义是什么意思?

来自分类Dev

定义lambda时[&]是什么意思?

来自分类Dev

这样的定义是什么意思?

来自分类Dev

以下结构定义是什么意思?

来自分类Dev

定义宏时`(...)`是什么意思?

来自分类Dev

BigDecimal的定义是什么意思?

来自分类Dev

MonadReader 的实例定义是什么意思?

来自分类Dev

全局format()函数是什么意思?

Related 相关文章

热门标签

归档