请问一下如何建一个自己的库
例如我有这样的两个文件
//mylib.h #ifndef _MYLIB_H #define _MYLIB_H void swap(int &, int &); void selctionSort(int[], int); #endif
//mylib.cpp void swap(int &a, int &b){ int temp = a; a = b; b = temp; } void selectionSort(int array[], int size){ int tempPos=0; for(int i=0; i<size; i++){ tempPos = i; for(int j=i+1; j<size; j++){ if(array[j] < array[tempPos]) tempPos = j; } swap(array[tempPos], array[i]); } }
#include "stdafx.h"#include <iostream>#include "D:\MYLIB\mylib.h"int _tmain(int argc, _TCHAR* argv[]){ int a[] = {0,2,5,1,5,6}; selctionSort(a, 6); for(int i = 0; i < 6; i++){ std::cout << a[i] << " "; } return 0;}
//void selctionSort(int[], int);void selectionSort(int[], int);