Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-04-2006, 08:44 PM   #1 (permalink)
fenderist
Recruit
 
Join Date: Sep 2006
Posts: 12
fenderist is on a distinguished road
Separate Compilation

These are exact copies of examples from my textbook.
when I tried to compile them
I got this message:

[Linker error] undefined reference to `WinMain@16'
ld returned 1 exit status

I tired to research on the internet,
some people recommended adding "int main()" to the implementation file, which did not work.
Please help me...

---------------------------dtime.cpp---------------------------
Code:
#include
#include
#include
#include "dtime.h"
using namespace std;

void read_hour(istream& ins, int& the_hour);

void read_minute(istream& ins, int& the_minute);

int digit_to_int(char c);

bool operator ==(const DigitalTime& time1, const DigitalTime& time2)
{
return (time1.hour == time2.hour && time1.minute == time2.minute);
}

DigitalTime::DigitalTime(int the_hour, int the_minute)
{
if (the_hour < 0 || the_hour > 23 || the_minute < 0 || the_minute > 59)
{
cout << "Illegal argument to DigitalTime constructor.";
exit(1);
}
else
{
hour = the_hour;
minute = the_minute;
}
}

DigitalTime::DigitalTime( ) : hour(0), minute(0)
{
//Body intentionally empty.
}

void DigitalTime::advance(int minutes_added)
{
int gross_minutes = minute + minutes_added;
minute = gross_minutes%60;

int hour_adjustment = gross_minutes/60;
hour = (hour + hour_adjustment)%24;
}

void DigitalTime::advance(int hours_added, int minutes_added)
{
hour = (hour + hours_added)%24;
advance(minutes_added);
}

//Uses iostream:
ostream& operator <<(ostream& outs, const DigitalTime& the_object)
{
outs << the_object.hour << ':';
if (the_object.minute < 10)
outs << '0';
outs << the_object.minute;
return outs;
}

//Uses iostream:
istream& operator >>(istream& ins, DigitalTime& the_object)
{
read_hour(ins, the_object.hour);
read_minute(ins, the_object.minute);
return ins;
}

int digit_to_int(char c)
{
return ( int(c) - int('0') );
}

//Uses iostream, cctype, and cstdlib:
void read_minute(istream& ins, int& the_minute)
{
char c1, c2;
ins >> c1 >> c2;

if (!(isdigit(c1) && isdigit(c2)))
{
cout << "Error illegal input to read_minute\n";
exit(1);
}

the_minute = digit_to_int(c1)*10 + digit_to_int(c2);

if (the_minute < 0 || the_minute > 59)
{
cout << "Error illegal input to read_minute\n";
exit(1);
}
}

//Uses iostream, cctype, and cstdlib:
void read_hour(istream& ins, int& the_hour)
{
char c1, c2;
ins >> c1 >> c2;
if ( !( isdigit(c1) && (isdigit(c2) || c2 == ':' ) ) )
{
cout << "Error illegal input to read_hour\n";
exit(1);
}

if (isdigit(c1) && c2 == ':')
{
the_hour = digit_to_int(c1);
}
else //(isdigit(c1) && isdigit(c2))
{
the_hour = digit_to_int(c1)*10 + digit_to_int(c2);
ins >> c2;//discard ':'
if (c2 != ':')
{
cout << "Error illegal input to read_hour\n";
exit(1);
}
}

if ( the_hour < 0 || the_hour > 23 )
{
cout << "Error illegal input to read_hour\n";
exit(1);
}
}
------------------------------dtime.h------------------------------
Code:
#include
using namespace std;

class DigitalTime
{
public:
friend bool operator ==(const DigitalTime& time1, const DigitalTime& time2);

DigitalTime(int the_hour, int the_minute);

DigitalTime( );

void advance(int minutes_added);

void advance(int hours_added, int minutes_added);

friend istream& operator >>(istream& ins, DigitalTime& the_object);

friend ostream& operator <<(ostream& outs, const DigitalTime& the_object);

private:
int hour;
int minute;
};
---------------------------timedemo.cpp:---------------------------
Code:
#include
#include "dtime.h"
using namespace std;

int main( )
{
DigitalTime clock, old_clock;

cout << "Enter the time in 24 hour notation: ";
cin >> clock;

old_clock = clock;
clock.advance(15);
if (clock == old_clock)
cout << "Something is wrong.";
cout << "You entered " << old_clock << endl;
cout << "15 minutes later the time will be "
<< clock << endl;

clock.advance(2, 15);
cout << "2 hours and 15 minutes after that\n"
<< "the time will be "
<< clock << endl;

return 0;
}
fenderist is offline   Reply With Quote
Old 11-04-2006, 09:56 PM   #2 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 598
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
What's with all the blank #include statements?
teknomage1 is offline   Reply With Quote
Old 11-07-2006, 01:29 PM   #3 (permalink)
fenderist
Recruit
 
Join Date: Sep 2006
Posts: 12
fenderist is on a distinguished road
Sorry about that... I do not know what went wrong...
Well, it is supposed to be like this:


---------------------------dtime.cpp---------------------------
#include <iostream>
#include <cctype>
#include <cstdlib>

------------------------------dtime.h------------------------------
#include <iostream>

---------------------------timedemo.cpp:---------------------------
#include <iostream>
fenderist is offline   Reply With Quote
Old 11-08-2006, 12:23 PM   #4 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
You didn't say in what compiler or environemnt this is happening. Usually it's missing headers or wrong project settings.
__________________
Valmont is offline   Reply With Quote
Old 11-11-2006, 11:09 AM   #5 (permalink)
fenderist
Recruit
 
Join Date: Sep 2006
Posts: 12
fenderist is on a distinguished road
I don't quite understand what you mean. Would you please explain more elaborately? Or an example would be nice.
fenderist is offline   Reply With Quote
Old 11-11-2006, 03:27 PM   #6 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 598
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
What did you type these examples into and what compiler did you use?

example1: I used Visual studio 6 on windows
example2: I used emacs and gcc on linux
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Old 11-11-2006, 03:28 PM   #7 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Like MS Visual Studio or CodeBlock or DevCPP etcetera.
__________________
Valmont is offline   Reply With Quote
Old 11-11-2006, 03:37 PM   #8 (permalink)
fenderist
Recruit
 
Join Date: Sep 2006
Posts: 12
fenderist is on a distinguished road
Oh... I am such a newb.
I have used Dev-C++ 5.0 beta 9.2 (4.9.9.2) (9.0 MB) with Mingw/GCC 3.4.2 on Windows
fenderist is offline   Reply With Quote
Old 11-12-2006, 11:53 AM   #9 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
In that case, if you start a new project with the main() in it only, do you still have that error message?
__________________
Valmont is offline   Reply With Quote
Old 11-19-2006, 04:56 PM   #10 (permalink)
fenderist
Recruit
 
Join Date: Sep 2006
Posts: 12
fenderist is on a distinguished road
I am very sorry for this late reply. For some reason, I did not get the email notification.
Well, I never used "project" before, but when created same files in it, it compiled without "main()" but it did not execute anything.
fenderist is offline   Reply With Quote
Old 11-19-2006, 09:01 PM   #11 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 598
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
I think it thinks you want to make a graphical application for windows, so it's making a winmain function for you, but since you probably didn't define any windows, it's exiting immediately. Is there an option to create a console application in the menu?
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Old 11-24-2006, 03:24 PM   #12 (permalink)
fenderist
Recruit
 
Join Date: Sep 2006
Posts: 12
fenderist is on a distinguished road
I have no clue.... I think I am just gonna give up on this. My prof. already gave me full credit, because he doesn't know either. O well, thanks for the help.
fenderist is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
compilation error i like c++ Standard C, C++ 1 02-21-2005 10:39 PM
Compilation errors. liguorir Standard C, C++ 2 05-23-2004 06:21 PM


All times are GMT -8. The time now is 09:32 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting