#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2009
    Posts
    34
    Rep Power
    0

    H and cpp files - trying to build a file


    Am I missing something in the h file? How can I get this to build?

    My h file
    Code:
    #include "test30.cpp"
    #include <iostream>
    My cpp file
    Code:
    #include <iostream>
    #include "test30.h"
    using namespace std;
    
    namespace first
    {
      int x = 5;
      int y = 10;
    }
    
    namespace second
    {
      double x = 3.1416;
      double y = 2.7183;
    }
    
    int main () {
      using first::x;
      using second::y;
      cout << x << endl;
      cout << y << endl;
      cout << first::y << endl;
      cout << second::x << endl;
      return 0;
    }
    I get the error:
    test30.cpp(2): fatal error C1014: too many include files : depth = 1024

    I bet someone on here can answer this in less than 10 seconds.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 2006
    Posts
    2,270
    Rep Power
    1736
    Why is the header file including the source file?

    EDIT: You wrote that line of code. I'm asking what motivated you to do so.
    When you ask a question, be prepared to tell us: what have you tried? If you think you don't need to try anything, we will never be interested in helping you. If you agree with the link, and you refuse to answer that question, you are being a hypocrite.

    Need help with broken code? Your question should be like a good bug report: (1) It has the smallest number of steps to reproduce the problem you see (2) It tells us precisely what you expected to see and (3) It tells us what you saw and how it differed from what you expected. We need all three to help you.
    Want better answers? Tell us what you Googled for and what steps you took to answer your own question.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2009
    Posts
    34
    Rep Power
    0
    kinda new to this. just trying things to get this to build.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 2006
    Posts
    2,270
    Rep Power
    1736
    kinda new to this. just trying things to get this to build.
    Yes, we can tell you are new. And it's obvious you want to fix the problems. I'm trying to get you to learn something here.

    You haven't answered my question.
    When you ask a question, be prepared to tell us: what have you tried? If you think you don't need to try anything, we will never be interested in helping you. If you agree with the link, and you refuse to answer that question, you are being a hypocrite.

    Need help with broken code? Your question should be like a good bug report: (1) It has the smallest number of steps to reproduce the problem you see (2) It tells us precisely what you expected to see and (3) It tells us what you saw and how it differed from what you expected. We need all three to help you.
    Want better answers? Tell us what you Googled for and what steps you took to answer your own question.
  8. #5
  9. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,075
    Rep Power
    1802
    File inclusion inserts the text of one source into another. What do you think happens when file A includes file B and file B includes file A? If the preprocessor or your IDE's dependency generator were not smart enough to spot it, a recursively infinitely growing file; that is what.

    It does not matter how new you are to something, most newbs start by copying something that works, and you will not have seen this any where.

    If that is your entire header file, it is entirely pointless, since if you remove the cpp inclusion (never include a cpp file BTW), you are left with <iostream> which your CPP file already includes. Nothing in your .cpp file needs anything that is not already in your cpp file or in iostream, so what is it for?

    If when you write 'sensible' code it does not compile, post the code and the compile log and we can help.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2009
    Location
    Georgia, USA
    Posts
    13
    Rep Power
    0
    Code:
    #include <iostream>
    using namespace std;
    
    int firstX() {
      return 5;
    };
    
    int firstY() {
      return 10;
    };
    
    double secondX() {
      return 3.1416;
    };
    
    double secondY() {
      return 2.7183;
    };
    
    
    
    int main () {
      cout << firstX() << endl;
      cout << firstY() << endl;
      cout << firstY() << endl;
      cout << secondX() << endl;
      cin.get();
      return 0;
    }
    I believe this is what you're trying to do?
    It should be just 1 file, if you're trying to do this ^.
    The only thing you need to include is iostream ;)

IMN logo majestic logo threadwatch logo seochat tools logo