-5

I am compiling a c++ program but i keep getting lines of code that make no sense and then at the bottom of it all it says "undefined reference to 'menu'". I have a .h file and a .cpp file, menu function is defined in my .h file, in my .cpp file i include my .h file at the top and this is also where I implement my menu function. And yes, I am compiling them at the same time

header file
#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 file
//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;
}
Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331
  • 1
    You have us guessing, Mr. NewbieOverHere. Why don't you reproduce your problem in the smallest possible form (removing unrelated stuff but still having the problem), and post the content of your files, as well as the command line you're using to compile? – salezica Jun 01 '16 at 00:03
  • 4
    Please include the relevant bits of code in your question. Also, welcome to Stack Overflow! If you want to try to improve you question please read http://stackoverflow.com/help/how-to-ask. – thesecretmaster Jun 01 '16 at 00:03
  • "*this is also where I implement my menu function*" OK, but where do you implement `main`? Did you forget to implement it at all? "*And yes, I am compiling them at the same time*" What "*them*"? You mentioned only one cpp file. – eerorika Jun 01 '16 at 00:05
  • 1
    Please [edit] your question to provide a [mcve]. – Baum mit Augen Jun 01 '16 at 00:06
  • 4
    Where's the `main` function? – Thomas Matthews Jun 01 '16 at 00:12
  • sorry new here. My problem is the error that I am getting when compiling. The 'menu' function cant be read. I compile my .h file and my .cpp file together – newbieoverhere Jun 01 '16 at 00:13
  • "I compile my .h file and my .cpp file together" - how are you doing this exactly ? (If using a commandline compiler then show the commandline) – M.M Jun 01 '16 at 00:25
  • Looks like, somewhere buried on your computer, is a cpp file with a `main` function. This function needs to be compiled and linked along with your .cpp file. – Thomas Matthews Jun 01 '16 at 00:34
  • 1
    Is it `menu` or is it `main` that's mentioned in the error message(s)? – Cheers and hth. - Alf Jun 01 '16 at 00:38
  • Rolled back edits that potentially/likely **changed the meaning** of the question. Don't do that. Please. – Cheers and hth. - Alf Jun 01 '16 at 00:51

1 Answers1

0

Every C++ program (for an ordinary hosted implementation) needs a main function; it can look like this:

int main()
{
    // Top level statements
}

main is automatically invoked when the program is run.

Some things, preparations, have to be done before main. These even include things specified by the programmer. So the invocation of main is not the very first that happens in your program, i.e. main is not the program's machine code level entry point, but it's the, well, the main thing.

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331