c++ - 声明与(方法)不兼容 - 指针

标签 c++ variables pointers

我最近开始玩 C++,但我不明白这意味着什么:

我收到此错误:

declaration is incompatible with "void student_system::addStudent(<error-type> z)" (declared at line 31)

同样适用于 removeStudent 和 editStudent

我从另一个 stackoverflow 帖子复制了“function()”,这看起来不错并且添加了标题没有问题,但我自己的“学生”方法似乎不起作用,我不明白为什么,

我还尝试添加指针而不是变量,但这也不起作用(指针我的意思是“student *x”)。

#include "database.h"
#include <vector>

int main()
{
    return 0;
}

class student_system
{   
private: 
    list<student> studList;

public:
    student_system();
    void addStudent(student x);
    void removeStudent(student y);
    void editStudent(student z);
    void findPos();
    void function(int a, int b, vector<int> *p);
};

student_system::student_system()
{
    //constructor
}

void student_system::addStudent(student x)               // <------------- LINE 31 
{
    studList.push_back(x);
}
void student_system::removeStudent(student y)
{
    /*studList.rem*/
}

void student_system::editStudent(student z)
{
    /*get{ return value; }
        set{  }*/

}

void student_system::findPos()
{

}

void student_system::function(int a, int b, vector<int> *p)
{

}



class student
{
private:
    string name, surname, ID;
    int sid;
public : 
    student::student(int sid, string n, string s, string id);
};

student::student(int sid, string n, string s, string id)
{
    (*this).sid = sid;
    (*this).name = n;
    (*this).surname = s;
    (*this).ID = id;    
}

最佳答案

放这段代码

class student
{
private:
    string name, surname, ID;
    int sid;
public : 
    student::student(int sid, string n, string s, string id);
};

就在

之后
#include <vector>

这样 student_system 及其定义就知道了

关于c++ - 声明与(方法)不兼容 - 指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34554788/

相关文章:

c++ - 陷入 std::function 和成员函数指针的困惑:(

variables - 如何在 emacs org 模式下设置变量值?

variables - SAS 中的动态变量名称

c - 动态内存分配代码解释

c++ - 改变这个指针指向的值

c++:复制ctor和指针

C++ 隐式类型转换

c++ - 检查未释放的指针

c++ - _CrtSetBreakAlloc 使用内存内容而不是分配号

javascript - document.location.href 重置全局变量