I am having problems compiling and running this program

This is a discussion on I am having problems compiling and running this program within the C++ Programming forums, part of the General Programming Boards category; insert Code: #ifndef EMPLOYEE_TYPE_FLAG #define EMPLOYEE_TYPE_FLAG #include <iostream> using namespace std; struct employee_type { char ssn[10]; employee_type() { ssn[0]='

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    10

    I am having problems compiling and running this program

    insert
    Code:
    #ifndef EMPLOYEE_TYPE_FLAG
    #define EMPLOYEE_TYPE_FLAG
    
    #include <iostream>
    using namespace std;
    
    
    
    struct employee_type
    {
        char ssn[10];
     
     
        employee_type()
        {
            ssn[0]='\0';
        }
    
        bool operator > (employee_type &e)
        {
            return strncmp(this->ssn, e.ssn, 10) >0;
        }
        bool operator < (employee_type &e)
        {
            return strncmp(this->ssn, e.ssn, 10) <0;
        }
          bool operator >= (employee_type &e)
        {
            return strncmp(this->ssn, e.ssn, 10) >=0;
        }
        
          bool operator <= (employee_type &e)
        {
            return strncmp(this->ssn, e.ssn, 10) <=0;
        }
          bool operator != (employee_type &e)
        {
            return strncmp(this->ssn, e.ssn, 10) !=0;
        }
    
        employee_type &operator = (employee_type &e)
        {
            strncpy(this->ssn, e.ssn, 10);
            return *this;
        }
    
        friend ostream &operator<<(ostream &os, employee_type &e)
        {
            os<<e.ssn<<'\n';
            return os;
        }
        
    int main()
    {
    cout << "Test" << endl;
    }
    };
    #endif
    This is the code i am getting this error:
    ld returned 1 exit status
    [Linker error] undefined reference to `WinMain@16'

    Does anyone know a solution to this?

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    In C++ you don't put the main function into a class/struct, it's a free function (Actually it seems like a hideous practice in C# tutorials that the main function belongs to some rather arbitrary class.)

    Next you'll need to include <cstring> for functions like strncpy.

    It is also unclear whether this is supposed to be a header (include guards)? Headers on their own are not supposed to be compileable.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    10
    Thanks. But im still getting the same error. I commented out the other headers. This is what I have:
    Code:
    //#ifndef EMPLOYEE_TYPE_FLAG
    //#define EMPLOYEE_TYPE_FLAG
    
    #include <iostream>
    #include <cstring>
    using namespace std;
    
    
    
    struct employee_type
    {
        char ssn[10];
     
     
        employee_type()
        {
            ssn[0]='\0';
        }
    
        bool operator > (employee_type &e)
        {
            return strncmp(this->ssn, e.ssn, 10) >0;
        }
        bool operator < (employee_type &e)
        {
            return strncmp(this->ssn, e.ssn, 10) <0;
        }
          bool operator >= (employee_type &e)
        {
            return strncmp(this->ssn, e.ssn, 10) >=0;
        }
        
          bool operator <= (employee_type &e)
        {
            return strncmp(this->ssn, e.ssn, 10) <=0;
        }
          bool operator != (employee_type &e)
        {
            return strncmp(this->ssn, e.ssn, 10) !=0;
        }
    
        employee_type &operator = (employee_type &e)
        {
            strncpy(this->ssn, e.ssn, 10);
            return *this;
        }
    
        friend ostream &operator<<(ostream &os, employee_type &e)
        {
            os<<e.ssn<<'\n';
            return os;
        }
        
    
    };
    //#endif
    I am getting the same error. Any reason why?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You need to have a main function, in order to have a program.

  5. #5
    Registered User
    Join Date
    Aug 2009
    Posts
    10
    What should or could I put in the main function

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Your previous main function was fine. It just needs to be there, not part of your employee struct.

  7. #7
    Registered User
    Join Date
    Aug 2009
    Posts
    10
    Code:
    //#ifndef EMPLOYEE_TYPE_FLAG
    //#define EMPLOYEE_TYPE_FLAG
    
    #include <iostream>
    using namespace std;
    
    
    
    struct employee_type
    {
        char ssn[10];
     
     
        employee_type()
        {
            ssn[0]='\0';
        }
    
        bool operator > (employee_type &e)
        {
            return strncmp(this->ssn, e.ssn, 10) >0;
        }
        bool operator < (employee_type &e)
        {
            return strncmp(this->ssn, e.ssn, 10) <0;
        }
          bool operator >= (employee_type &e)
        {
            return strncmp(this->ssn, e.ssn, 10) >=0;
        }
        
          bool operator <= (employee_type &e)
        {
            return strncmp(this->ssn, e.ssn, 10) <=0;
        }
          bool operator != (employee_type &e)
        {
            return strncmp(this->ssn, e.ssn, 10) !=0;
        }
    
        employee_type &operator = (employee_type &e)
        {
            strncpy(this->ssn, e.ssn, 10);
            return *this;
        }
    
        friend ostream &operator<<(ostream &os, employee_type &e)
        {
            os<<e.ssn<<'\n';
            return os;
        }
        int main()
    {
    cout << "Test" << endl;
    }
    
    };
    //#endif
    I have that now. And still getting the same error. hmm

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    It's still inside the struct definition. Put it after the closing brace.

  9. #9
    Registered User
    Join Date
    Aug 2009
    Posts
    10
    Now it compiled. Thanks alot. I am now asked to write a drivers program for it. I have never written one before but this is what I have. I do not believe I am doing it right. Can anyone verify or tell me what I need to do/change.

    Code:
    #include<iostream>
    
    using namespace std;
    
    
    int main()
    {
        
        int e1=1111; 
        int e2=2222;
        
        if (e1 > e2)
        cout << "Good" << endl;
        else 
        {
             cout << "Bad" << endl;
        }
        cout << "-------------------------------------" << endl << endl;
        
        if (e1 < e2)
        cout << "Good" << endl;
        else 
        {
             cout << "Bad" << endl;
        }
        cout << "-------------------------------------" << endl << endl;
        
        if (e1 >= e2)
        cout << "Good" << endl;
        else 
        {
             cout << "Bad" << endl;
        }
        cout << "-------------------------------------" << endl << endl;
        
        if (e1 <= e2)
        cout << "Good" << endl;
        else 
        {
             cout << "Bad" << endl;
        }
        cout << "-------------------------------------" << endl << endl;
        
        if (e1 != e2)
        cout << "Good" << endl;
        else 
        {
             cout << "Bad" << endl;
        }
         cout << "-------------------------------------" << endl << endl;
        
        if (e1 == e2)
        cout << "Good" << endl;
        else 
        {
             cout << "Bad" << endl;
        }
         cout << "-------------------------------------" << endl << endl;
        
        
        
    
    
    system("pause");
    
    return 0;
    }

  10. #10
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    C Board - Homework Policy

    What are you trying to do, what have you tried, why are you doing it that way?

    'Seek and ye shall find', but first you need to provide details of what you are seeking.

    99% of the time, when someone is asking US for help on their homework, they should be asking the instructor. After all, any help he gives you won't be considered an honor code violation.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  11. #11
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    >> I am now asked to write a drivers program for it.

    A driver program is a program that takes the struct or class you have (in this case it would be the employee_type struct) and uses the functions provided by the struct to show that they work.

    Your attempt at a driver program does not use the struct. Change it to use the struct.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling C sharp program
    By pokhara in forum C# Programming
    Replies: 4
    Last Post: 07-29-2009, 02:44 PM
  2. Problem Running Program After Compiling
    By kristentx in forum C++ Programming
    Replies: 13
    Last Post: 09-12-2007, 11:46 AM
  3. Error running program in cmd - cygwin.dll missing -
    By JFonseka in forum C Programming
    Replies: 5
    Last Post: 08-27-2007, 01:12 PM
  4. Replies: 6
    Last Post: 07-20-2007, 10:23 AM
  5. Running a program
    By dingolay in forum C Programming
    Replies: 4
    Last Post: 10-01-2006, 10:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21