Thread: Help with referencing

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    26

    Help with referencing

    I am getting an error message when trying to run this program using a Visual C++ 6.0 compiler. The header and code is straight out of the book and I need to understand why I am getting this error message.....maybe I am not compiling correctly? Any help please.?

    This is the header file correct?
    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

    This is the source code correct?
    Code:
    // 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
    Either way I get the same fatal error that #include “time3.h” is a problem. What am I doing wrong?

  2. #2
    meow nbk's Avatar
    Join Date
    Jul 2004
    Posts
    45
    Possibly the place where MSC++ points too to look for headers? Make sure it has the path to look for headers where the custom header is.

  3. #3
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    I got a whole bunch of linker errors when i tried it is that what your getting because if it is. It's because the functions that you are using have not been implimented just prototyped
    Woop?

  4. #4
    Registered User
    Join Date
    Jul 2004
    Posts
    26
    Quote Originally Posted by nbk
    Possibly the place where MSC++ points too to look for headers? Make sure it has the path to look for headers where the custom header is.
    These are two examples out of my textbook that produce output. For my homework I have to change the first part to do something else, so I figured I would see how the example works from the book.

    The way I understand it from the example is that the custom header is the first part. and the error I keep getting is on the path part. (according to the pseudocode saying that it is the path)

  5. #5
    Registered User
    Join Date
    Jul 2004
    Posts
    26
    Quote Originally Posted by prog-bman
    I got a whole bunch of linker errors when i tried it is that what your getting because if it is. It's because the functions that you are using have not been implimented just prototyped
    I got the linker errors also at first because I didnt open the c++ program as a Windows 32 Console application. When I closed it and reopened it it only gave me my above error.

  6. #6
    Registered User
    Join Date
    Jul 2004
    Posts
    26
    Quote Originally Posted by nbk
    Possibly the place where MSC++ points too to look for headers? Make sure it has the path to look for headers where the custom header is.
    Hold on. Now when I tried to restart my program I saw the choice of a file that supports MSC. What is MSC and could this be the problem?

  7. #7
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    No what im saying is where are the functions defined at i don't see it unless im being blind. The things that do this
    Code:
    void time::setHour(int)
    {
      //blah
    }
    Woop?

  8. #8
    Registered User
    Join Date
    Jul 2004
    Posts
    26
    Quote Originally Posted by daisy244
    Hold on. Now when I tried to restart my program I saw the choice of a file that supports MSC. What is MSC and could this be the problem?

    when running the program this is the error message I get

    c:\program files\microsoft visual studio\myprojects\pooeo\hss.cpp(43) : fatal error C1083: Cannot open include file: 'time3.h': No such file or directory

  9. #9
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Is time3.h in the same directory as hss.cpp? cause that will throw vc++ off
    Last edited by prog-bman; 07-28-2004 at 09:08 PM.
    Woop?

  10. #10
    Registered User
    Join Date
    Jul 2004
    Posts
    26
    Quote Originally Posted by prog-bman
    Is time3.h in the same directory as hss.cpp? cause that will throw vc++ off
    I guess I dont understand directories. Ive tried it with the whole program in one C++ Source File...Build....same message. I have also tried it by putting the first part in a C++ Header File and then open a C++ Source file and place the second part in it.....same message. How do I put it in a different directory?

  11. #11
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    ok try this
    File->New->Win32 Console(Test)->Empty Project->Finish
    File->New->c/c++ header file(Test)
    File->New->c++ source file(Test)
    copy time3.h into test.h
    copy hss.cpp into test.cpp
    Woop?

  12. #12
    Registered User
    Join Date
    Jul 2004
    Posts
    26
    Quote Originally Posted by prog-bman
    ok try this
    File->New->Win32 Console(Test)->Empty Project->Finish
    File->New->c/c++ header file(Test)
    File->New->c++ source file(Test)
    copy time3.h into test.h
    copy hss.cpp into test.cpp
    did it......got the same message

  13. #13
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    can you post the whole error output for me?
    Woop?

  14. #14
    meow nbk's Avatar
    Join Date
    Jul 2004
    Posts
    45
    bman - does vc++ have a place to add directories to look for for include files(as does dev-c++)

  15. #15
    Registered User
    Join Date
    Jul 2004
    Posts
    26
    Quote Originally Posted by prog-bman
    can you post the whole error output for me?
    c:\program files\microsoft visual studio\myprojects\test\test.cpp(9) : fatal error C1083: Cannot open include file: 'time3.h': No such file or directory
    Error executing cl.exe.

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

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