Thread: Help with referencing

  1. #16
    Registered User
    Join Date
    Jul 2004
    Posts
    26
    Quote Originally Posted by nbk
    bman - does vc++ have a place to add directories to look for for include files(as does dev-c++)
    this is a beginning c++ course. deitel vsn. 4 it came with the visual c++ compiler

  2. #17
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    grr i know why :P
    try including test.h and not time3.h
    and nbk when you create a project with vc++ the directory you put it in is searched as well as the include directory
    Woop?

  3. #18
    Registered User
    Join Date
    Jul 2004
    Posts
    26
    Quote Originally Posted by prog-bman
    grr i know why :P
    try including test.h and not time3.h
    and nbk when you create a project with vc++ the directory you put it in is searched as well as the include directory
    Duh, that makes sense....its pointing to the file. Well bad news I got these 10 errors.

    Linking...
    test.obj : error LNK2001: unresolved external symbol "public: void __thiscall Time::setTime(int,int,int)" (?setTime@Time@@QAEXHHH@Z)
    test.obj : error LNK2001: unresolved external symbol "public: int __thiscall Time::getHour(void)" (?getHour@Time@@QAEHXZ)
    test.obj : error LNK2001: unresolved external symbol "public: int __thiscall Time::getMinute(void)" (?getMinute@Time@@QAEHXZ)
    test.obj : error LNK2001: unresolved external symbol "public: int __thiscall Time::getSecond(void)" (?getSecond@Time@@QAEHXZ)
    test.obj : error LNK2001: unresolved external symbol "public: void __thiscall Time::setSecond(int)" (?setSecond@Time@@QAEXH@Z)
    test.obj : error LNK2001: unresolved external symbol "public: void __thiscall Time::setMinute(int)" (?setMinute@Time@@QAEXH@Z)
    test.obj : error LNK2001: unresolved external symbol "public: void __thiscall Time::setHour(int)" (?setHour@Time@@QAEXH@Z)
    test.obj : error LNK2001: unresolved external symbol "public: __thiscall Time::Time(int,int,int)" (??0Time@@QAE@HHH@Z)
    test.obj : error LNK2001: unresolved external symbol "public: void __thiscall Time:rintStandard(void)" (?printStandard@Time@@QAEXXZ)
    Debug/test.exe : fatal error LNK1120: 9 unresolved externals
    Error executing link.exe.

    test.exe - 10 error(s), 0 warning(s)

  4. #19
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    there are the errors i got basically that means you are calling a function that hasn't been defined yet
    Woop?

  5. #20
    Registered User
    Join Date
    Jul 2004
    Posts
    26
    Quote Originally Posted by prog-bman
    there are the errors i got basically that means you are calling a function that hasn't been defined yet
    ok I think I got it. thanks alot

  6. #21
    Registered User
    Join Date
    Jul 2004
    Posts
    26
    Quote Originally Posted by daisy244
    ok I think I got it. thanks alot
    Ok I figured it out and got it to work. Now I have to change this code in the header to include a tick memeber function that increments the time stored in the time object by one second any suggestions? By what I am looking at.....it looks like it should do it already. but I think in my cpp part it is only changing it by minutes? Am I right?
    Code:
    Fig. 6.18: time3.h 
    // Declaration of class Time. 
    // Member functions defined in time3.cpp 
    
    // prevent multiple inclusions of header file 
    #ifndef TIME3_H  
    #define TIME3_H 
    
    class Time { 
    
    public: 
       Time( int = 0, int = 0, int = 0 );  // default constructor 
    
       // set functions 
       void setTime( int, int, int );  // set hour, minute, second 
       void setHour( int );   // set hour 
       void setMinute( int ); // set minute 
       void setSecond( int ); // set second 
    
       // get functions 
       int getHour();         // return hour 
       int getMinute();       // return minute 
       int getSecond();       // return second 
    
       void printUniversal(); // output universal-time format 
       void printStandard();  // output standard-time format 
    
    private: 
       int hour;              // 0 - 23 (24-hour clock format) 
       int minute;            // 0 - 59 
       int second;            // 0 - 59 
    
    }; // end clas Time 
    
    #endif

  7. #22
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    These are just prototypes can you show me the definitions?
    Woop?

  8. #23
    Registered User
    Join Date
    Jul 2004
    Posts
    26
    Quote Originally Posted by prog-bman
    These are just prototypes can you show me the definitions?
    With the header file already stored in its directory: I put this in the cpp source file built it and it gave me the output I was searching for:
    Code:
    // Fig. 6.19: time3.cpp
    // Member-function definitions for Time class.
    #include <iostream>
    
    using std::cout;
    
    #include <iomanip>
    
    using std::setfill;
    using std::setw;
    
    // include definition of class Time from time3.h
    #include "time3.h"
    
    // constructor function to initialize private data;
    // calls member function setTime to set variables;
    // default values are 0 (see class definition)
    Time::Time( int hr, int min, int sec ) 
    { 
       setTime( hr, min, sec ); 
    
    } // end Time constructor
    
    // set hour, minute and second values
    void Time::setTime( int h, int m, int s )
    {
       setHour( h );
       setMinute( m );
       setSecond( s );
    
    } // end function setTime
    
    // set hour value
    void Time::setHour( int h ) 
    {
       hour = ( h >= 0 && h < 24 ) ? h : 0; 
    
    } // end function setHour
    
    // set minute value
    void Time::setMinute( int m )
    { 
       minute = ( m >= 0 && m < 60 ) ? m : 0; 
    
    } // end function setMinute
    
    // set second value
    void Time::setSecond( int s )
    { 
       second = ( s >= 0 && s < 60 ) ? s : 0; 
    
    } // end function setSecond
    
    // return hour value
    int Time::getHour() 
    { 
       return hour; 
    
    } // end function getHour
    
    // return minute value
    int Time::getMinute() 
    {
       return minute; 
    
    } // end function getMinute
    
    // return second value
    int Time::getSecond() 
    { 
       return second;
       
    } // end function getSecond
    
    // print Time in universal format
    void Time::printUniversal()
    {
       cout << setfill( '0' ) << setw( 2 ) << hour << ":"
            << setw( 2 ) << minute << ":"
            << setw( 2 ) << second;
    
    } // end function printUniversal
    
    // print Time in standard format
    void Time::printStandard()
    {
       cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 )
            << ":" << setfill( '0' ) << setw( 2 ) << minute
            << ":" << setw( 2 ) << second 
            << ( hour < 12 ? " AM" : " PM" );
    
    } // end function printStandard
    // Fig. 6.20: fig06_20.cpp
    // Demonstrating the Time class set and get functions
    #include <iostream>
    
    using std::cout;
    using std::endl;
    
    // include definition of class Time from time3.h
    #include "time3.h"
    
    void incrementMinutes( Time &, const int );  // prototype
    
    int main()
    {
       Time t;              // create Time object
    
       // set time using individual set functions
       t.setHour( 17 );     // set hour to valid value
       t.setMinute( 34 );   // set minute to valid value
       t.setSecond( 25 );   // set second to valid value
    
       // use get functions to obtain hour, miunute and second
       cout << "Result of setting all valid values:\n" 
            << "  Hour: " << t.getHour()
            << "  Minute: " << t.getMinute()
            << "  Second: " << t.getSecond();
    
       // set time using individual set functions
       t.setHour( 234 );    // invalid hour set to 0
       t.setMinute( 43 );   // set minute to valid value
       t.setSecond( 6373 ); // invalid second set to 0
    
       // display hour, minute and second after setting 
       // invalid hour and second values
       cout << "\n\nResult of attempting to set invalid hour and"
            << " second:\n  Hour: " << t.getHour()
            << "  Minute: " << t.getMinute()
            << "  Second: " << t.getSecond() << "\n\n";
    
       t.setTime( 11, 58, 0 );    // set time
       incrementMinutes( t, 3 );  // increment t's minute by 3
    
       return 0;
    
    } // end main
    
    // add specified number of minutes to a Time object
    void incrementMinutes( Time &tt, const int count )
    {
       cout << "Incrementing minute " << count
            << " times:\nStart time: ";
       tt.printStandard();
    
       for ( int i = 0; i < count; i++ ) {
          tt.setMinute( ( tt.getMinute() + 1 ) % 60 );  
    
          if ( tt.getMinute() == 0 )
             tt.setHour( ( tt.getHour() + 1 ) % 24 );
    
          cout << "\nminute + 1: ";
          tt.printStandard();
    
       } // end for
    
       cout << endl;
    
    } // end function incrementMinutes

  9. #24
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Yep i just kept seeing declarations and no definations that looks good to me
    Woop?

  10. #25
    Registered User
    Join Date
    Jul 2004
    Posts
    26
    Quote Originally Posted by prog-bman
    Yep i just kept seeing declarations and no definations that looks good to me
    what do you mean by definitions?

  11. #26
    meow nbk's Avatar
    Join Date
    Jul 2004
    Posts
    45
    A definition is where you define the function(correct?)

    e.g.

    Code:
    int main()    // Define main()
    {                 //   Still...
         int var;       //   :o          
    {                // yay
    
    
    int main();           //declare main(which you never do :), unless the compiler requires it)
    Last edited by nbk; 07-29-2004 at 09:50 PM.

  12. #27
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Declarations and prototype are when you just have the functions name, return type, and parameters, but no code for the functions. It's like declaring a variable (int x) but not defining it yet (x = 5). Show the code to your functions.

    edit: nbk is basically correct, but I wouldn't recommend looking at that code.

  13. #28
    Registered User
    Join Date
    Jul 2004
    Posts
    26
    Quote Originally Posted by sean_mackrory
    Declarations and prototype are when you just have the functions name, return type, and parameters, but no code for the functions. It's like declaring a variable (int x) but not defining it yet (x = 5). Show the code to your functions.

    edit: nbk is basically correct, but I wouldn't recommend looking at that code.
    This program is referencing this header file:
    Code:
    Fig. 6.18: time3.h 
    // Declaration of class Time. 
    // Member functions defined in time3.cpp 
    
    // prevent multiple inclusions of header file 
    #ifndef TIME3_H  
    #define TIME3_H 
    
    class Time { 
    
    public: 
       Time( int = 0, int = 0, int = 0 );  // default constructor 
    
       // set functions 
       void setTime( int, int, int );  // set hour, minute, second 
       void setHour( int );   // set hour 
       void setMinute( int ); // set minute 
       void setSecond( int ); // set second 
    
       // get functions 
       int getHour();         // return hour 
       int getMinute();       // return minute 
       int getSecond();       // return second 
    
       void printUniversal(); // output universal-time format 
       void printStandard();  // output standard-time format 
    
    private: 
       int hour;              // 0 - 23 (24-hour clock format) 
       int minute;            // 0 - 59 
       int second;            // 0 - 59 
    
    }; // end clas Time 
    
    #endif
    Notice that it says Member functions defined in time3.cpp

  14. #29
    Registered User
    Join Date
    Jul 2004
    Posts
    26
    Ive got to change time.h to increment with a tick command to make the output increment in seconds.

  15. #30
    Registered User
    Join Date
    Jul 2004
    Posts
    26
    Quote Originally Posted by daisy244
    Ive got to change time.h to increment with a tick command to make the output increment in seconds.
    Are you through with helping me? Let me know?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Symbol Referencing Error
    By Delpheno in forum C++ Programming
    Replies: 3
    Last Post: 01-31-2008, 09:03 PM
  2. Symbol referencing errors
    By n00pster in forum C++ Programming
    Replies: 9
    Last Post: 04-30-2007, 06:40 AM
  3. STL list and referencing
    By gautamn in forum C++ Programming
    Replies: 1
    Last Post: 06-13-2005, 12:40 AM
  4. Problem in table referencing
    By elquex in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2003, 03:00 AM
  5. referencing structure variables
    By sballew in forum C Programming
    Replies: 1
    Last Post: 11-01-2001, 01:56 PM