-5
我正在编译一个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;
}
你有我们猜测,先生NewbieOverHere。为什么不以最小的可能形式重现问题(删除不相关的东西但仍然存在问题),并发布文件的内容以及用于编译的命令行? – slezica
请在您的问题中包含相关的代码位。另外,欢迎来到Stack Overflow!如果您想尝试改善您的问题,请阅读http://stackoverflow.com/help/how-to-ask。 – thesecretmaster
“*这也是我实现我的菜单功能的地方*”好的,但是你在哪里实现'main'?你忘了执行它了吗? “*是的,我正在同时编译它们*”什么“*他们*”?你只提到一个cpp文件。 – user2079303