错误:"Undefined reference to 'main'"
Error: "Undefined reference to 'main'"
我正在编译一个c++程序,但我不断得到毫无意义的代码行,然后在它的底部写着"对‘菜单’的未定义引用"。我有一个.h文件和一个.cpp文件,菜单函数在我的.h文件中定义,在我的.cpp文件中,我在顶部包含了我的.h.文件,这也是我实现菜单函数的地方。是的,我正在同时编译
头文件#include <iostream>
#include <cctype>
#include <fstream>
using namespace std;
/*
struct dog_park
{
char * name;
char * location;
char * description;
char * fence;
char * size;
};
*/
class parks
{
public:
struct dog_park
{
char * name;
char * location;
char * description;
char * fence;
char * size;
};
parks();
int menu();
bool display_all();
void add_park();
bool search_park();
~parks();
private:
dog_park * all_parks;
int length;
};
.cpp文件//implementation of functions
#include "cs162_parks.h"
parks::parks()
{
all_parks = new dog_park[length];
}
//allows for user to select what action to take
int parks::menu()
{
int choice = 0;
cout << "Welcome to the menu, your choices to choose from are: " << endl << endl;
cout << "1. Add a dog park to list" << endl;
cout << "2. Search for specific park by name" << endl;
cout << "3. Display all dog parks" << endl;
cout << "4. Quit" << endl << endl;
cout << "What menu selection do you choose? (1-4): ";
cin >> choice;
cin.ignore(100, 'n');
return choice;
}
parks::~parks()
{
if (all_parks)
delete [] all_parks;
}
每个C++程序(对于普通托管实现)都需要一个main
函数;它可以看起来像这样:
int main()
{
// Top level statements
}
程序运行时会自动调用main
。
有些事情,准备工作,必须在main
之前完成。这些甚至包括程序员指定的东西。因此,main
的调用并不是程序中发生的第一次调用,即main
不是程序的机器代码级入口点,但它是最重要的。
相关文章:
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- 代码在main()中运行,但在函数中出现错误
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- Visual Studio Code "undefined reference to `WinMain@16'"
- 当我在main中声明了我的2d数组时,为什么我的程序会退出
- QML:修改在不同QML文件(而非main.QML)中定义的子对象的属性
- 使用 MATLAB 编码器生成C++代码:编译错误"undefined reference to `rgb2gray_tbb_real64'"
- 不确定要在我的main中放入什么才能使我的代码正常工作
- 函数是否可以访问传递给main()的参数
- 使用 [] 运算符时"binding reference of type discards qualifiers"
- 在main()之外初始化std::vector会导致性能下降(多线程)
- 为什么创建友元类的实例会导致"undefined reference to"错误?
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 我的 int main() 中出现堆栈溢出错误
- C++变量名(可以将 main 声明为变量,但对于其他函数名称则不然)
- Tensorflow c++ api undefined reference to 'tflite::D efaultErrorReporter()'
- 为什么我会"undefined reference to main"
- 错误:"Undefined reference to 'main'"
- 我收到错误:"in function main: undefined reference to Fraction::Fraction()"
- No compila el main:undefined reference to main'