gpt4 book ai didi

c++ - 未定义对 'class::function' 的引用?

转载 作者:行者123 更新时间:2023-11-28 06:04:42 24 4
gpt4 key购买 nike

<分区>

好吧,我还在习惯 C++,所以这个错误可能看起来很简单。我正在尝试创建一个具有三个成员函数的简单类(我只是想在此调用其中一个)。所以我创建了类,实例化了一个对象,然后尝试使用该对象调用函数,但出现了这个错误:

Code.cpp:(.text+0x15): 对 `Code::genCode()' 的 undefined reference

我已经仔细检查过是否是函数本身的错误,但事实并非如此。我看过其他人关于这个问题的帖子,但似乎有多种情况和解决方案。无论如何,这是代码:

#include <vector>
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <list>
using namespace std;

class Code {
public:
int genCode();
int checkCorrect();
int checkIncorrect();
};

int main()
{
Code c1;
c1.genCode();
}

////////////////FUNCTIONS/////////////////////////
int genCode()
{
vector <int> newcode;
srand(time(NULL));
for(int i = 0; i < 9; i++){
int x;
x = (rand() % 6);
if (find(newcode.begin(),newcode.end(), x) == newcode.end())
{
newcode.push_back(x);
}
}
if (newcode.size() > 4)
{
newcode.pop_back();
}
for(int i = 0; i < 4; i++)
{
return newcode[i];
}
}

int checkCorrect()
{

}

int checkIncorrect()
{

}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com