Hello to all. I have a question. I started learning C ++ Conlose Application. I have a project, it has 2 files: main.cpp and hello.cpp. And in the first one I registered a call to hello.cpp. But he writes a mistake

1>c:\users\владик\documents\visual studio 2010\projects\myfirstprogramm\myfirstprogramm\hello.cpp(2): fatal error C1014: слишком много включаемых файлов: глубина = 1024 1> hello.cpp 1>c:\users\владик\documents\visual studio 2010\projects\myfirstprogramm\myfirstprogramm\hello.cpp(2): fatal error C1014: слишком много включаемых файлов: глубина = 1024 1> Создание кода...

Code in 1 program

 #include <iostream> #include "hello.cpp" int main() { Hello.cpp(); return 0; } 

And in hello.cpp

 #include <iostream> #include "hello.cpp" int main() hellow.cpp void hellow() { printf("Hellow"); } 

Where is the mistake? This is a video tutorial. Here is the link .

  • @RconPro, To format the code, select it with the mouse and click on the button 101010 of the editor. - Nicolas Chabanovsky

3 answers 3

Usually everyone starts header files (usually it is .h) (in general, what includes #include) is this:

 #ifndef MY_FILE_123_H #define MY_FILE_123_H .... #endif 

This prevents looping, and simply provides a one-time code substitution.

Sometimes (for example, stdlib.h or stdio.h #define are tricky, depending on a number of conditions)

    The error is that with the preprocessor directive #include you connect hello.cpp. By connecting hello.cpp from hello.cpp, you get recursion, which the preprocessor cuts off after 1024 nested inclusions.

    And in the video, the author (by the way, all familiar faces - hello to Eugene Linsky!) Creates a separate header file hello.h, in which he places the function prototype from hello.cpp. So watch the lesson carefully!

    • Mlin, well, when will everyone teach With how he - through tench and gcc? !!! - skegg
    • For the sake of interest, I took and watched this lecture from beginning to end. Really 80% of the time is empty writing on the board. Is that the way they are taught now in the institutes? However, we probably had about the same. - Naturally, then the students have such a misunderstanding. - avp
    • @mikillskegg, all - not soon, but the trend is there. - northerner
    • And it will come true when C is on prevalence equal to PL / I. - alexlz
    • one
      Well, if KOI-7, it means it is not necessary to explain the term "Mongolian text". And Stepanov - the author of stl (he jokingly told some Italians in an interview that STL stands for Stepanov and Lee - his assistant) - alexlz

    Sorry, are you calling hello.cpp from main.cpp? Maybe you want to call the function specified in this file? I don’t understand what the hello.cpp () line does.

    Added from comment .

     //main.cpp #include "hello.cpp" int main() { hellow(); return 0; } //hello.cpp #include <stdio.h> void hellow() { printf("Hellow"); } 
    • I want to call Hello.срр from Mein - RconPro
    • Please make a formatting view of the file codes - carapuz
    • And return 0; no need to add? - RconPro
    • hellow () of type void. She returns nothing - carapuz