Trying to get this to compile is driving me nuts! Any help is greatly appreciated. I think it's having trouble linking the header to the .cpp files. It's my first program in Dev C++ - I'm used to using Visual Studio.

Here's the source for the header header:

#include <iostream>
#include <stdlib.h>
#include "SmpMth.h"
using namespace std;

int SmpMth::Add(int a, int b)
//Postcondition:
//              The sum of two ints is returned                
{
    return a+b;
}

int SmpMth::Max(int a, int b)
//Postcondition:
//              The maximum of two ints is returned
{
    if(a>b)
    {
           return a;
    }
    else
           return b;
}

int SmpMth::Min(int a, int b)
//Postcondition:
//              The minimum of two ints is returned
{
    if(a<b)
           return a;
    else
           return b;
}

and here's the header:

#include <iostream>
#include <stdlib.h>
using namespace std;

class SmpMth
{
      public:
             int Add(int, int);
             int Max(int, int);
             int Min(int, int);
               SmpMth();
               SmpMth(int, int);
      private:
              
};

Thanks in advance for any help,
Nate

Sorry, I forgot to say what the error message is comming back as. Here's the error:
[Linker error] undefined reference to `WinMain@16'
ld returned 1 exit status

Thanks again,
Nate

you probably created the wrong kind of project. You should have created a Console Application, not a Windows Application. With a Console Application your program compiled with no errors or warnings. Of course I had to add a main() function to the code you posted.

Thanks, but I didn't even make it an application of either type to begin with. I just opened up new source files each time, and saved them as a .h and .cpp files. I also had another .cpp file that I was using in conjunction... here's the code for that one:

#include <iostream>
#include <stdio.h>
#include "SmpMth.h"
using namespace std;

//This is only a test driver for the SmpMth class

int main()
{
    int a,b;
    char var;
    
    cout<<"******Min, Max & Add********\n"
        <<"\n\n";

     cout<<"Add two numbers together: ";
     cin>>a,b;
     cout<<"\n"  <<Add(a,b) <<"\n";
      
        
    system("PAUSE");    
    return 0;
}

Hope this helps a little more, sorry I didn't think to include it to begin with.

Thanks, but I didn't even make it an application of either type to begin with. I just opened up new source files each time, and saved them as a .h and .cpp files.

Well, if you are going to use Dev-C++ then do it right. Create a project and then add the code to it.

This article has been dead for over six months. Start a new discussion instead.