From here you will have to write the code for your classes, properties and functions that you need to implement. Let's write some simple functions for our libraries. First we need to create one header file to declare the two functions. These functions will be named add and multiply.
Each function will receive two integer arguments, and return an integer value.
#ifndef __MY_MATH_LIB__
#define __MY_MATH_LIB__
int add(int number_a, int number_b);
int multiply(int number_a,int number_b);
#endif
Now that they are declared, let's write the definition of our functions in a .cpp file:
#include"MyMathLib.h"
int add(int number_a, int number_b)
{
return (number_a) + (number_b);
}
int multiply(int number_a,int number_b)
{
return (number_a) * (number_b);
}
Press F7 to build the library solution. If we go to our Debug or Release folder (depending our compiling configuration), our output file will be the static library. That means our library can be implemented in any Visual C++ project. Let's use these functions in a Console Application.
Create a cpp file for Win32 Application project and write the following code:
#include<iostream> #include"../MyMathLib/MyMathLib.h" //Path of your declared methods
usingnamespace std;
int main ()
{
cout <<"Testing my math lib" << endl;
cout <<"Please enter a number ";
int number_a, number_b;
cin >> number_a;
cout <<"Please enter another number ";
cin >> number_b;
cout <<"The addition result for these numbers is ";
cout << add(number_a, number_b);
cout << endl;
cout <<"The multiply result for these numbers is ";
cout << multiply(number_a, number_b);
cout << endl;
system("pause");
return 0;
}