Code Reuse From Another Project

Hello programmers,

I am using Microsoft Visual C++ 2008.
I am building a project which makes use of classes I built in previous projects.

Instead of making another copy of the code and place it in the project currently building, is there a way to make reference to code I wrote in other projects?

I heard that it can be done by Project Dependencies.
I tried to link projects with Project Dependencies and include header files in other projects. It doesn't seems to work.
The MSDN documentation is very vague and doesn't solve the problem.

In short, I would like to re-use code from another project in the current project. Would anyone kindly explain how to achieve this?
Last edited on
Just copy the appropriate .cpp and .hpp files over to the new project's directory, and add them to the project from the projects menu.

Project Dependencies are for managing which library files (.lib and .dll) are linked to your executable.
Thanks. But is there a way to avoid copy and paste? As each time I edit my code, I have to copy and paste again.
I'm confused. Are you destroying the files each time you edit your project?
Last edited on
I guess Duoas means that if he has code in one project which he copies to another project then if he makes a change to that code he has to copy the modied code to the other project in order to reflect those modifcation there.
What he wants is to be able to point to an arbitary directly in the project settings so the compiler / linker will also search there so that 2 (or more) projects could point to the same directory so you would only need to make any changes in a single place.
Unfortunately I don't know how to set this up:-(
closed account (z05DSL3A)
Can you not just go to the Project menu and select Add existing Item or press Shift+ALT+A and add the existing source files to the project? Or have I misunderstood?

If you want to include the whole of another project, go to the File->Add->Existing Project... menu.
Last edited on
Topic archived. No new replies allowed.