0

Well I have made separate programs for testing and debugging purposes and now I want to put them together. Is it possible to use one .cpp as some sort of a header file, and call it later on? I saw it done before but I think it was a makefile(which I don't really know much about yet) but I want to know if it's possible in a normal project.

I use CodeBlocks as my main IDE but the question is in general

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Dexxta27
0

using one *.cpp as an include in another *.cpp is a BIT NO-NO. Create a project and add both *.cpp files to it. The compiler will compile each *.cpp file and then link them both together, along with other libraries that the program may use. You will see the advantage of this when you get a project that contains hundreds of *.cpp files.

Edited by Ancient Dragon: n/a

0

So I can call one *.cpp in another if they are in the same project then? I have about 15 different files so it would be helpful.

0

Yes, any function in one *.cpp can be called from functions in other *.cpp files. That's how multi-file projects work, and is identical approach taken when functions in the standard C or C++ libraries are called. What you will want to do is put all the function prototypes in a *.h file and include that *.h file in each of the *.cpp files.

Edited by Ancient Dragon: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.