Export (0) Print
Expand All

Creating Reusable Code (C++)

Now that we have learned how to use the Visual Studio IDE and how to create command-line and Windows applications, we will learn how to write code so that it can be used by multiple applications. One way to do this is to create a library that contains related classes and algorithms. For example, Visual C++ is included with many libraries that any C or C++ application can use, such as the C Run-Time Library and the Standard C++ Library. Without these libraries, there would be no standard way for a C or C++ application to write to the console or determine the current date and time.

Every C or C++ application will likely use one of the previously mentioned libraries. You can also create your own libraries of classes and algorithms that any application can use. With Visual C++, you can create three kinds of libraries:

  • Dynamic link libraries (DLLs).

  • Static libraries.

  • Managed assemblies.

In general, if you are creating a library that can be used by native C++ code, you will create either a dynamic link library or a static library. For more information about how to determine which type of library to create, see DLLs. If you are creating a library that can be used by C++/CLI or any other .NET language such as C# or Visual Basic, you will create a managed assembly.

In this section, we will create a simple library of standard math operations such as addition and multiplication, and we will show how applications can use this library.

These topics assume that you understand the fundamentals of the C++ language. If you are just getting started learning C++, we recommend the "C++ Beginner's Guide," written by Herb Schildt, available online at http://go.microsoft.com/fwlink/?LinkId=115303.

Community Additions

© 2014 Microsoft