Compilation Errors

This is a discussion on Compilation Errors within the C++ Programming forums, part of the General Programming Boards category; I have 5 files Clock.cc Clock1.cc Clock.h Clock1.h and Main.cc Clock1 inherits from Clock. I have tried to compile my ...

  1. #1
    Registered User nevermind's Avatar
    Join Date
    Oct 2002
    Posts
    23

    Compilation Errors

    I have 5 files Clock.cc Clock1.cc Clock.h Clock1.h and Main.cc

    Clock1 inherits from Clock.

    I have tried to compile my program in Borland and it works nicely (but as one file Clock.cpp not as a project of multiple files).

    But when I try to compile my files in G++ ; I break them up into seperate files like clock.h clock1.h etc. it gives me so many errors. I know I have not typed the header part of each file correctly. Could anyone please have a look and let me know please.
    Code:
    **Main.CC**
    
    #include<iostream>
    #include "Clock.h"
    #include "Clock1.h"
    
    using namespace std;
    
    int main()
    {
    
       int hours, mins, secs;
       char amPM;                       //To store whether AM or PM
       Clock c;                         //Object creation of class Clock.
       int stop;                        //To store temporary user input.
    
       Clock *p1, *p2, *p3, *p4, *p5;     //Set Clock objects which are pointers
       Clock1 ny, lon, sing, cape, syd;   //Set Zonal clocks for each city
    
    ...
    }
    
    **Clock.cc**
    
    
    #include<iostream>
    #include<time.h>
    #include "Clock.h"
    
    using namespace std;
    
    Clock :: Clock()
    {
       hh = mm = ss = 0;        
       timerSecs = 0;
    }
    ...
    
    
    **Clock.h**
    
    
    #ifndef CLOCK_H
    #define CLOCK_H     
    
    class Clock{
       protected:
          int hh, mm, ss;          
          
    
    ...
    
    }
    
    
    **Clock1.cc**
    
    #include<iostream>
    #include "Clock1.h"
    #include "Clock.h"
    
    using namespace std;
    
    Clock1 :: Clock1     //Constructor
    {
    }
    ...
    
    
    **Clock1.h**
    
    #ifndef CLOCK_H
    #define CLOCK_H     
    #include "Clock.h"
    
    class Clock1 : public Clock       //for zonal clocks
    {
       public:
    ...


    I have only included the top bits because I feel sure that nothing is wrong with the program as it compiles fine in Borland under Windows.

    Any suggestions or help will be greatly appreciated. I am new at this!

    Thanks


    Code tags added by kermi3

  2. #2
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595

    Code Tags

    I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happy about helping you


    For example:

    Without code tags:

    for(int i=0;i<5;i++)
    {
    cout << "No code tags are bad";
    }

    With Code Tags:
    Code:
    for(int i=0;i<5;i++)
    {
         cout << "This code is easy to read";
    }
    This is of course a basic example...more complicated code is even easier to read with code tags than without.

    I've added code tags for you this time. They can be added by putting [code] at the beginning of your code and [/code] at the end. More information on code tags may be found at the link in my signature. I also suggest you take a look at the board guildlines if you have not done so already. Any further questions or ways I can help please feel free to PM me.

    This is a common first post mistake, just remember to use [code] tags in the future and you'll get much more help.

    Good Luck,
    Kermi3
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  3. #3
    Registered User nevermind's Avatar
    Join Date
    Oct 2002
    Posts
    23

    whoops

    Oh no forgot about the tags sorry bout that ... will not forget!

    Cheers!

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>... it gives me so many errors.
    So, what are they then? Post your errors too (or some of them, if you are getting tons...)
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User nevermind's Avatar
    Join Date
    Oct 2002
    Posts
    23

    errors

    Code:
    Clock1.cc:26: `hh' undeclared (first use this function)
    Clock1.cc:26: (Each undeclared identifier is reported only once
    Clock1.cc:26: for each function it appears in.)
    Clock1.cc:27: `mm' undeclared (first use this function)
    Clock1.cc:28: `ss' undeclared (first use this function)
    Clock1.cc: At top level:
    Clock1.cc:34: invalid use of undefined type `class Clock1'
    Clock1.h:15: forward declaration of `class Clock1'
    Clock1.cc: In method `void Clock1::show_time()':
    Clock1.cc:36: implicit declaration of function `int add_time(...)'
    Clock1.cc:39: `period' undeclared (first use this function)  
    
    and so many more ...
    
    Main.cc: In function `int main()':
    Main.cc:24: `Clock1' undeclared (first use this function)
    Main.cc:24: (Each undeclared identifier is reported only once
    Main.cc:24: for each function it appears in.)
    Main.cc:24: parse error before `,'

  6. #6
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    fix all your parse errors then come back, as a parse error will often spawn many other errors with it
    hello, internet!

  7. #7
    Registered User nevermind's Avatar
    Join Date
    Oct 2002
    Posts
    23
    Hmmm ... yeah I'll do that thanks for the tip.

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    81
    well, I'm not one to usually give help on this board, since I'm no pro by any means, but it seems that you are getting the same errors I was getting just moments ago.

    If your trying to compile in Unix like I just was, you have to make sure that all of your lines are on the same lines. For example, if you have
    <i>
    some line that takes
    two lines
    </i>

    just make sure that you fix it as

    <i>some line that takes one line </i>

    I had a ton of errors and once I fixed that simple problem, they all went away.

    Hope this helps!

  9. #9
    Registered User nevermind's Avatar
    Join Date
    Oct 2002
    Posts
    23

    Thank you all very much

    Thanks for all your help!

    It really helped me today.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking and compilation errors
    By _lazycat_ in forum Windows Programming
    Replies: 2
    Last Post: 02-13-2009, 07:16 AM
  2. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 04:11 PM
  3. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 11:50 AM
  4. Winsock compilation errors
    By jmd15 in forum Networking/Device Communication
    Replies: 2
    Last Post: 08-03-2005, 09:00 AM
  5. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21