944,184 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2066
  • C++ RSS
Sep 10th, 2005
0

Help please, getting this to compile (using Dev C++)

Expand Post »
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:
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include "SmpMth.h"
  4. using namespace std;
  5.  
  6. int SmpMth::Add(int a, int b)
  7. //Postcondition:
  8. // The sum of two ints is returned
  9. {
  10. return a+b;
  11. }
  12.  
  13. int SmpMth::Max(int a, int b)
  14. //Postcondition:
  15. // The maximum of two ints is returned
  16. {
  17. if(a>b)
  18. {
  19. return a;
  20. }
  21. else
  22. return b;
  23. }
  24.  
  25. int SmpMth::Min(int a, int b)
  26. //Postcondition:
  27. // The minimum of two ints is returned
  28. {
  29. if(a<b)
  30. return a;
  31. else
  32. return b;
  33. }

and here's the header:
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <stdlib.h>
  3. using namespace std;
  4.  
  5. class SmpMth
  6. {
  7. public:
  8. int Add(int, int);
  9. int Max(int, int);
  10. int Min(int, int);
  11. SmpMth();
  12. SmpMth(int, int);
  13. private:
  14.  
  15. };

Thanks in advance for any help,
Nate
Similar Threads
Reputation Points: 14
Solved Threads: 1
Light Poster
Coach_Nate is offline Offline
48 posts
since Aug 2004
Sep 10th, 2005
0

Re: Help please, getting this to compile (using Dev C++)

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
Reputation Points: 14
Solved Threads: 1
Light Poster
Coach_Nate is offline Offline
48 posts
since Aug 2004
Sep 10th, 2005
0

Re: Help please, getting this to compile (using Dev C++)

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,963 posts
since Aug 2005
Sep 11th, 2005
0

Re: Help please, getting this to compile (using Dev C++)

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:
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include "SmpMth.h"
  4. using namespace std;
  5.  
  6. //This is only a test driver for the SmpMth class
  7.  
  8. int main()
  9. {
  10. int a,b;
  11. char var;
  12.  
  13. cout<<"******Min, Max & Add********\n"
  14. <<"\n\n";
  15.  
  16. cout<<"Add two numbers together: ";
  17. cin>>a,b;
  18. cout<<"\n" <<Add(a,b) <<"\n";
  19.  
  20.  
  21. system("PAUSE");
  22. return 0;
  23. }

Hope this helps a little more, sorry I didn't think to include it to begin with.
Reputation Points: 14
Solved Threads: 1
Light Poster
Coach_Nate is offline Offline
48 posts
since Aug 2004
Sep 11th, 2005
0

Re: Help please, getting this to compile (using Dev C++)

Quote originally posted by Coach_Nate ...
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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,963 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Need some advice on a fairly big project
Next Thread in C++ Forum Timeline: Simple Class Question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC