0

Всем привет. Есть 3 файла:

//header.h
#ifndef _HEADER_H_
#define _HEADER_H_

template <typename T> 
void Convertation(T*, const short size);

const short SIZE = 9;

#endif
//help.cpp
#include "header.h"

template <typename T> 
void Convertation(T* array, const short size)
{
    for (short counter = 0; counter != size / 2; ++counter)
    {
        *(array + counter) ^= *(array + (size - 1) - counter);
        *(array + (size - 1) - counter) ^= *(array + counter);
        *(array + counter) ^= *(array + (size - 1) - counter);
    }
}
//code.cpp
#include <iostream>
#include "header.h"

int main(void)
{
    short array[SIZE] {5, 4, 3, 2, 1};

    std::cout << "There are source array:\n";

    for (short counter = 0; counter < SIZE; ++counter)
        std::cout << "array[" << counter << "] = " << array[counter] << std::endl;

    Convertation(array, SIZE);
    std::cout << "There are modificated array:\n";

    for (short counter = 0; counter < SIZE; ++counter)
                std::cout << "array[" << counter << "] = " << array[counter] << std::endl;

    return 0;
}

При компиляции: g++ code.cpp help.cpp

Ошибка:

/usr/bin/ld: /tmp/cckx4G1e.o: in function `main':
code.cpp:(.text+0xea): undefined reference to `void Convertation<short>(short*, short)'
collect2: error: ld returned 1 exit status

Ubuntu OS.

Danny
  • 430
  • https://ru.stackoverflow.com/questions/579322/%d0%a0%d0%b0%d0%b7%d0%b4%d0%b5%d0%bb%d1%8c%d0%bd%d0%b0%d1%8f-%d0%ba%d0%be%d0%bc%d0%bf%d0%b8%d0%bb%d1%8f%d1%86%d0%b8%d1%8f-%d1%88%d0%b0%d0%b1%d0%bb%d0%be%d0%bd%d0%bd%d1%8b%d1%85-%d0%ba%d0%bb%d0%b0%d1%81%d1%81%d0%be%d0%b2?rq=1 – IR42 Mar 21 '20 at 23:41
  • Для чего нужна раздельная компиляция? Вот когда ответите на этот вопрос, то вам самим будет понятно, что нет смысла пытаться разделять объявление и определение шаблона, особенно, что это не сработает никак – AR Hovsepyan Mar 22 '20 at 00:02
  • https://www.cyberforum.ru/cpp-beginners/thread1798717.html – Croessmah stands with Russia Mar 22 '20 at 05:47

0 Answers0