GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 28-Aug-2007, 06:47
Afroze Afroze is offline
New Member
 
Join Date: Aug 2007
Posts: 2
Afroze is on a distinguished road

problem about linker error


CPP / C++ / C Code:
#include<iostream>
using namespace std;

#include "Time.h"


int main()
{
  Time t;
  
  cout<<"the intial universal time is ";
  t.printuniversal();
  cout<<"\n the intial standard time is ";
  t.printstandard();
  
  
  t.settime(13,27,6);
  
  
  cout<<"\n\n universal time after settime is";
  t.printuniversal();
  cout<<"\n standard time after settime is";
  t.printstandard();
  
  t.settime(99,99,99);
  
  cout<<"\n\n after attempting invalid settings:"
  <<"\n universal time " ;
  t.printuniversal();
  cout<<"\n standard time";
  t.printstandard();
  cout<<endl;
return 0;
}
///////implemetation file
#include<iostream>
#include<iomanip>  
using namespace std;

Time::Time()
{
   hour=minute=second=0;
}

void Time::settime()
{
  hour=(h>=0&&h<24)?h:0;
  minute(m>=0&&m<60)?m:0;
  second(s>=0&&s<60)?s:0;
}

void Time::printuniversal()
{
   cout<<setfill('0')<<setw(2)<<hour<<":"
   <<setw(2)<<minute<<":"<<setw()<<second;
}

void Time::printstandard()
{
  cout<<((hour==0)||(hour==12)?12:hour%12)<<":"
  <<setfill('0')<<setw(2)>>minute<<":"<<setw(2)<<second<<(hour<12?"AM":"PM") 
}     
 ////// //.h file              
#ifndef TIME_H
#define TIME_H


class Time
{
  public:
       Time();
       void settime(int,int,int);
       void printuniversal();
       void printstandard();
   private:
        int hour;
        int minute;
        int second;
        
        };
        
        #endif
Last edited by LuciWiz : 28-Aug-2007 at 11:29. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #2  
Old 28-Aug-2007, 08:54
Kimmo Kimmo is offline
Member
 
Join Date: Mar 2007
Location: Finland
Posts: 229
Kimmo has a spectacular aura aboutKimmo has a spectacular aura about

Re: problem about linker error


Pay attention. Check the method declaration, definitions. Really. Don't just look "ok that's fine", LOOK at them and compare.
  #3  
Old 28-Aug-2007, 19:19
davis
 
Posts: n/a

Re: problem about linker error


Quote:
Originally Posted by Afroze
CPP / C++ / C Code:
#include<iostream>
using namespace std;

#include "Time.h"


int main()
{
  Time t;
  
  cout<<"the intial universal time is ";
  t.printuniversal();
  cout<<"\n the intial standard time is ";
  t.printstandard();
  
  
  t.settime(13,27,6);
  
  
  cout<<"\n\n universal time after settime is";
  t.printuniversal();
  cout<<"\n standard time after settime is";
  t.printstandard();
  
  t.settime(99,99,99);
  
  cout<<"\n\n after attempting invalid settings:"
  <<"\n universal time " ;
  t.printuniversal();
  cout<<"\n standard time";
  t.printstandard();
  cout<<endl;
return 0;
}
///////implemetation file
#include<iostream>
#include<iomanip>  
using namespace std;

Time::Time()
{
   hour=minute=second=0;
}

void Time::settime()
{
  hour=(h>=0&&h<24)?h:0;
  minute(m>=0&&m<60)?m:0;
  second(s>=0&&s<60)?s:0;
}

void Time::printuniversal()
{
   cout<<setfill('0')<<setw(2)<<hour<<":"
   <<setw(2)<<minute<<":"<<setw()<<second;
}

void Time::printstandard()
{
  cout<<((hour==0)||(hour==12)?12:hour%12)<<":"
  <<setfill('0')<<setw(2)>>minute<<":"<<setw(2)<<second<<(hour<12?"AM":"PM") 
}     
 ////// //.h file              
#ifndef TIME_H
#define TIME_H


class Time
{
  public:
       Time();
       void settime(int,int,int);
       void printuniversal();
       void printstandard();
   private:
        int hour;
        int minute;
        int second;
        
        };
        
        #endif

You're calling and declaring settime( with three integers ), but your implementation is settime( void )...the linker can't find your implementation of settime with three integer arguments.


:davis:
  #4  
Old 30-Aug-2007, 11:03
Afroze Afroze is offline
New Member
 
Join Date: Aug 2007
Posts: 2
Afroze is on a distinguished road

Re: problem about linker error


thanks for ur reply , i tired then also it is showing the same problem and i am not understanding the problem.
  #5  
Old 30-Aug-2007, 11:17
davis
 
Posts: n/a

Re: problem about linker error


Quote:
Originally Posted by Afroze
thanks for ur reply , i tired then also it is showing the same problem and i am not understanding the problem.

CPP / C++ / C Code:
void Time::settime()
{
  hour=(h>=0&&h<24)?h:0;
  minute(m>=0&&m<60)?m:0;
  second(s>=0&&s<60)?s:0;
}

...is your implementation.

CPP / C++ / C Code:
t.settime(13,27,6);

...is how you're trying to use it.

CPP / C++ / C Code:
void settime(int,int,int);

...is how it is declared.

You have not implemented a version of settime that takes (int, int, int) so the linker can not find that version of the function. Because that version is being used by your code, it MUST find it in order to link an executable. Therefore, it fails and will not link.

Since you are not using settime(void) just change your implementation to accept and use the three integer values that you want to give to it.


:davis:
  #6  
Old 30-Aug-2007, 11:24
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,688
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: problem about linker error


Quote:
Originally Posted by Afroze
thanks f...it is showing the same problem...

The code in your original post has numerous compile-time errors, but the title of your thread is "problem about linker error". If you really compiled all of that code together, it could never get to the linker.

1. Post the exact code that you are actually getting a "linker error" from.

2. Post the exact error message (paste it directly into your post; don't paraphrase).

3. Tell us what compiler you are using.

4. Tell us how you compiled the code (command line or what).

Regards,

Dave
 
 

Recent GIDBlogWelcome to Baghdad by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linked Lists advice request promsan C Programming Language 74 23-May-2007 08:29
Major newbie problem cynack MS Visual C++ / MFC Forum 1 08-Apr-2007 11:25
Winsock error when compiling FLTK 2.0 Projects mauriciorossi FLTK Forum 3 16-Aug-2005 10:18
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 20:30
What is "Ambigious symbol" ??*( a compilation error) small_ticket C++ Forum 2 07-Jan-2005 21:10

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 05:22.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.