0

I'm working on a utility (for practice) that has two tools that a user can run.

I want to know if there's an outer layer within a solution where I can build classes that are recognized by all projects of said solution.

I'm at the point where both tools are finished and I want to add the two projects to one solution. However, these tools can share a few non-static classes and I really want to avoid having multiple of the same .cpp/.h files for each project so if I need to edit or add to a shared class, I don't have to copy/paste the edits into each project.

I tried using resource files, but they won't add .h or .cpp files. I tried adding the classes to their own project and then using them as references in the other projects, but the classes within the other projects won't recognize them. I also looked around at creating a library, but I'm not sure if it's possible to create non-static libraries as these projects will have multiple objects of the shared classes.

I'm very visual and I'm not sure if I explained my issue well so here's a simple diagram of what I want. Each arrow shows who each project can "be aware of" so-to-speak (conceptually similar to class inheritance). The bold First Project is the solution's entrance; essentially just where the user specifies which tool to run.

File structure diagram

Ausche
  • 139
  • 2
  • 12

1 Answers1

1

From what you described a class library would be the solution. This would allow you to share your two classes between both projects. In C++ there are two types of class libraries the Static Link Library and the Dynamic Link Library.

Here is a nice answer from a previous StackOverflow question which should aid you in determining which type of class library to use.

I have also included two separate links from Microsoft, since you tagged your post with Visual Studio, on how to create and use a library of each type.

MSDN: Static Link Library Tutorial

MSDN: Dynamic Link Library Tutorial

Community
  • 1
  • 1
Craig K
  • 86
  • 1
  • 5
  • Thank you, I'm still learning how to make libraries so I wasn't sure if that was the solution. Is it possible to create dynamic or static link libraries with classes with non-static member-functions though? I need to be able to create modifiable objects from these classes and the tutorials only show static-type member functions. – Ausche Mar 22 '17 at 18:55
  • @Ausche Yes you can use non-static methods. The examples only used static method for brevity. – Craig K Mar 22 '17 at 19:15
  • Awesome I'm going to try this out. Thank you! – Ausche Mar 22 '17 at 19:26