gpt4 book ai didi

C++ 错误 : undefine reference to main in class

转载 作者:行者123 更新时间:2023-11-30 02:13:42 30 4
gpt4 key购买 nike

<分区>

我在 Linux 中使用代码块。当我尝试在定义了类 Position 的地方构建我的 cpp 文件时,它给出了一个错误-

in function '_start':
undefined reference to 'main'

即使在创建了目标文件之后。

All this files are in the same folder

这是定义Position的cpp文件

#include "POSITION.h"

std::string Position::pos(int num) {
switch(num) {
case 0: return "\0";
break;
case 1: return "st";
break;
case 2: return "nd";
break;
case 3: return "rd";
break;
default: return "th";
break;
}
}

这是头文件

#pragma once
#include <iostream>

class Position
{
public:
std::string pos(int num);
};

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