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

Recommended Answers

All 4 Replies

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.

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.

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.

Thank you very much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.