2

I am practicing with OOP in C++. The problem I am working on requires 2 classes, one for a patient and another for a medical procedure performed. I wrote a header and class implementation file for the patient class. The header file compiled without a problem, but for some reason the .cpp file keeps giving me:

undefined reference to 'winmain'. Error ID returned 1 exit status.

I am new to OOP, and have already tried reviewing the book required for class and searching for the answer to no avail.

Header file:

#ifndef Patient_h
#define Patient_h
#include <string>

using std::string;
class Patient
{
    private:
        string name, address, phone, e_contact;
    public:
        Patient(string n = " ", string a = "", string p = "", string e_con = "")
            {
                name = n; address = a; phone = p; e_contact = e_con;
            }
        void setName();
        void setAddress();
        void setPhone();
        void setContact();
        string getName();
        string getAddress();
        string getPhone();
        string getContact();

};
#endif

And the cpp file:

#include "Patient.h"
#include <iostream>
using std::cout; using std::cin;
void Patient::setName()
{
    cout << "Enter the Patient's full name.  First, middle and last.\n";
    getline(cin, name);
    cin.ignore();
}
void Patient::setAddress()
{
    cout << "Enter the Patient's address.  Street, city and state + zipcode.\n";
    getline(cin,address);
    cin.ignore();
}
void Patient::setPhone()
{
    cout << "Enter the patient's phone number.\n";
    getline(cin,phone);
    cin.ignore();
}
void Patient::setContact()
{
    cout << "Please enter the patient's emergency contact name and phone.\n";
    getline(cin, e_contact);
    cin.ignore();
}
string Patient::getName()
{
    return name;
}
string Patient::getAddress()
{
    return address;
}
string Patient::getPhone()
{
    return phone;
}
string Patient::getContact()
{
    return e_contact;
}
Christophe
  • 68,716
  • 7
  • 72
  • 138
AKO
  • 39
  • 3
  • 1
    When a program is created, it needs an entry point, in other words, a point that is called when you start running a program. In c/c++, that point is a function called main. In MS windows, that point is called `winmain` for windows application and `main` for console application. In the code that you have shown, you are not providing any of those functions – Amadeus Jan 11 '20 at 23:42
  • Okay. Based on what I have learned, when working with classes it is best to separate the class into a header file, an implementation file for the class member functions and the main program. Even when I write the main program, it still gives me that error. I appreciate the info, but I am still lost. – AKO Jan 12 '20 at 00:16
  • You haven't shown us your main program. Does your main program start with `main`? That means that it's a console app, but you configured your project as a GUI app. Set your project as a console app. – Raymond Chen Jan 13 '20 at 20:35
  • Does this answer your question? [undefined reference to WinMain, \[Error\] Id returned 1 exit status](https://stackoverflow.com/questions/21652922/undefined-reference-to-winmain-error-id-returned-1-exit-status) – Raymond Chen Jan 13 '20 at 20:36

1 Answers1

0

The problem is not a compiling problem but a linking problem.

According to your explanations, you will have several files to compile:

 Patient.h
 Patient.cpp    --> Implementation --> object module 
 Procedure.h
 Procedure.cpp  --> Implementation  --> object module
 ...

Once all the files are compiled and the corresponding binary object modules were created, the linker will put the pieces together and create an executable file.

But to create an executable, the linker must also know where the programm execution should start. This is called the entry point.

In C++ the entry point is normally the main() function. If you do not have one yet, there's something missing to finish the build process.

In you case, the linker claims a winmain function. This is a bad thing for you: this means that the settings of your project tell the IDE that you want to create a GUI application for windows, and not a command line application.

Since you use cout and normal console I/O, I think that you do not intend to do GUI programme and that the GUI is a wrong setting. You must find how to change this setting in the IDE.

Christophe
  • 68,716
  • 7
  • 72
  • 138