Share headers between two projects - c++

My project is in Visual Studio Express 2013. I have one Solution for my game called Game. Within the solution I have two Projects one called Client and one called Server. I wrote a Class called Game. I also wrote two more Classes, Client and Server, both inherit from the Game class. I have separate .cpp and .h files for each class. How can I use these files in both projects? I'd like to create a Client object in the client project and a Server object in the server project. Is this possible? Am I going about this the wrong way? I'm trying to use classes more.

Related

Sharing classes within one solution

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.
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

How to "sync" two project inside the same solution?

I've these project inside Visual Studio 2015:
as you can see, they "share" the same classes (.cpp/.h). If I edit it inside DefaultProject-app, automatically it change within DefaultProject-vst2.
Now, I want to make a new class, and I want the same for it. So right click to DefaultProject-app->Add->Class. But once I create it, it place only in DefaultProject-app. It should be in both project, and compile when I compile one of the other.
How can I do it? Somethings like "Build Phases" in Xcode?
If you have classes that are used by more than one project, the best approach is to create a new third project that both DefaultProject-app and DefaultProject-vst2 can both reference. This is one of the foundations of programming: a library with common classes and functions.

How to structure solution for client server in visual studio

I am new to networking and I am trying to make a basic client and server app.
I would like to know how I can structure my solution in visual studio for this.
What I have now is two projects - one for the client, one for the server. However, both the client and server use code from certain source files that are 'shared' if you would. Common purpose functions, etc.
Since both applications will need this code compiled, do I need to copy these source files in both the client and server project, or is there another, perhaps better way?

Extending a class between two Visual Studio C++ projects

Please have a look at the following diagram
This is socket programming. Server is one VS Project. Client is another VS project. But, they both extend one class!!! How can I extend a class between 2 VS applications???? Please help!
Put the base class in a header file which is visible and accessible to both projects. #include that file from those projects and extend the base class.
In Visual Studio, you can make a solution which contains projects.

Referencing an unmanaged C++ project within another unmanaged C++ project in Visual Studio 2008

I am working on a neural network project that requires me to work with C++. I am working with the Flood Neural Network library. I am trying to use a neural network library in an unmanaged C++ project that I am developing. My goal is to create an instance of a class object within the Flood library from within another project.
There is plenty of documentation online regarding how to reference an unmanaged C++ project from within a C# project, but there is not enough information on how to reference one C++ project within another. Similar to how I would do it in C#, I added the Flood project as a reference in my other project, but I have tried all sorts of techniques to work with the object. I have attempted to use the #include directive to reference the header file, but that gives me errors stating that I need to implement the methods declared in the header file.
How to add a reference in unmanaged C++ and work with the class objects?
Yes. You need to do two things:
#include the respective header files, as you did
Add a reference (Visual C++ supports two types, "dependencies" which are outdated and should not be used anymore, and "references" which are the correct ones). Use them to reference the other project, which must be a part of your solution. Meaning, in this case you must be able to COMPILE the other project.
Alternatively, if you do not have the source code, or you do not wish to compile the 3rd-party code for any other reason, you may also reference a compiled binary. The best way to do it is pragma comment lib. If this is what you need, please comment and I will edit my response.
Looking at the provided vcproj file, the flood distribution is really weird, and builds an exe file.
As such, the supported way to use Flood in your own project is not via two projects (being your application and a "libflood" project) - But simply to add all the flood cpp files to your own project and build that.