I am trying to create a function that will take an array of any type and write it to another empty array, here is the code:
My main file:
#include "Education.h"
#include "Functions.h"
using namespace std;
int main() {
int numbers[] = { 0, 3, 1, 2, 5, 3, 9 };
int other_numbers[7];
copy_array(numbers, other_numbers);
return 0;
}
Functions.h:
#ifdef FUNCTIONS_H
#else
#include <iostream>
template <typename T>
void copy_array(const T* current_array, T* target_array);
#endif // FUNCTIONS_H'
Functions.cpp:
#include "Functions.h"
template<typename T>
void copy_array(const T* current_array, T* target_array)
{
if (sizeof(target_array) >= sizeof(current_array))
{
for (int i = 0; i < size(current_array); i++)
{
target_array[i] = current_array[i];
}
}
else
{
std::cout << "Very soon here will be an error throw.\n";
}
}
But I get this error:
>------ Build started: Project: CMakeLists, Configuration: Debug ------ [1/3] Building CXX object Education\CMakeFiles\Education.dir\Education.cpp.obj [2/3] Building CXX object Education\CMakeFiles\Education.dir\Functions.cpp.obj [3/3] Linking CXX executable Education\Education.exe FAILED: Education/Education.exe cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=Education\CMakeFiles\Education.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\mt.exe --manifests -- C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\MSVC\1434~1.319\bin\Hostx64\x64\link.exe /nologo Education\CMakeFiles\Education.dir\Education.cpp.obj Education\CMakeFiles\Education.dir\Functions.cpp.obj /out:Education\Education.exe /implib:Education\Education.lib /pdb:Education\Education.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ." LINK Pass 1: command "C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\MSVC\1434~1.319\bin\Hostx64\x64\link.exe /nologo Education\CMakeFiles\Education.dir\Education.cpp.obj Education\CMakeFiles\Education.dir\Functions.cpp.obj /out:Education\Education.exe /implib:Education\Education.lib /pdb:Education\Education.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:Education\CMakeFiles\Education.dir/intermediate.manifest Education\CMakeFiles\Education.dir/manifest.res" failed (exit code 1120) with the following output: C:\Users\Mondau\source\repos\Education\out\build\x64-debug\Education\Education.cpp.obj : error LNK2019: unresolved external symbol "void __cdecl copy_array<int>(int const *,int *)" (??$copy_array@H@@YAXPEBHPEAH@Z) referenced in function main
C:\Users\Mondau\source\repos\Education\out\build\x64-debug\Education\Education\Education.exe : fatal error LNK1120: 1 unresolved externals
ninja: build stopped: subcommand failed.
I will be very grateful if someone explains in which direction to search solution ^^