Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
#include <iostream>
using namespace std;
template<class T> void function(T *array, size_t size)
{
for (size_t i = 0; i < size; ++i)
cout << " " << array[i];
}
int main (int, char**)
{
int array[] = {4, -2, 3, 1, 30};
function(array, 5);
cout << endl;
return 0;
}
template<class T> void sortWithoutReturn(T *array, size_t size);
#ifndef FUNCTION_H
#define FUNCTION_H
template<class T> void function(T *array, size_t size);
#include "function.cpp"
#endif
#include "function.h"
using namespace std;
template<class T> void function(T *array, size_t size)
{
for (size_t i = 0; i < size; ++i)
cout << " " << array[i];
}
#include <iostream>
#include "function.h"
int main (int, char**)
{
int array[] = {4, -2, 3, 1, 30};
function(array, 5);
cout << endl;
return 0;
}
Bei Benedikts Lösung sollte man der Vollständigkeit halber die Datei aber nicht mehr Function.cpp nennen, sondern z.B FunctionImpl.h oder Function.inl (oder den Code gleich in den Header werfen).
Sonst musst du in deinem Buildsystem zwischen .cpp Dateien die selbst kompiliert, und solchen die nur inkludiert werden unterscheiden (wenn nicht werden die Files ja 2x kompiliert).