初学C++,这个程序为什么说没有定义?是模板函数哪里有问题吗?

daystudy.h

 #ifndef DAYSTUDY_H
#define DAYSTUDY_H
#define LENGTH 10
template <typename T>
int fillArr(T [],int);
template <typename T>
void modifyArr(T [],int);
template <typename T>
void displayArr(const T [],int);
#endif // DAYSTUDY_H

main.cpp

 #include <QCoreApplication>
#include <iostream>
#include <string>
#include "daystudy.h"
int main(int argc, char *argv[])
{
    bool continueProcess=true;
    int choice=0;
    float arr[LENGTH];
    int realLength=LENGTH;
    while(continueProcess){
        std::cout<<"菜单:"<<std::endl<<"1,填充数组\t2,修改数组\t3,显示数组"<<std::endl;
        while(!(std::cin>>choice)){
            std::cin.clear();
            char nextChar=std::cin.get();
            if(nextChar=='q'||nextChar=='Q'){
                continueProcess=false;
                break;
            }
            std::cin.sync();
            std::cout<<"输入数字选项!"<<std::endl;
        }
        if(!continueProcess){
            continue;
        }
        switch(choice){
        case 1:
            realLength=fillArr(arr,LENGTH);
            break;
        case 2:
            modifyArr(arr,realLength);
            break;
        case 3:
            displayArr(arr,realLength);
            break;
        default:
            std::cout<<"选项错误!"<<std::endl;
        }
    }
}

daystudy.fun.cpp

 #include <iostream>
#include "daystudy.h"
using std::cout;
using std::endl;
using std::cin;
template <typename T>
int fillArr(T arr[],int length){
    int realLength=0;
    bool continueFill=true;
    while(continueFill && realLength<length){
        cout<<"输入"<<realLength+1<<"个元素:";
        while(!(cin>>arr[realLength])){
            cin.clear();
            char nextChar=cin.get();
            if(nextChar=='q'||nextChar='Q'){
                continueFill=false;
                break;
            }
            cin.sync();
            cout<<"请输入正确的类型!"<<endl;
        }
    }
    return realLength;
}

template <typename T>
void modifyArr(T arr[],int length){
    int elementIndex=0;
    bool continueModify=true;
    while(continueModify){
        cout<<"输入元素索引:";
        while(!(cin>>elementIndex)){
            cin.clear();
            char nextChar=cin.get();
            if(nextChar=='q'||nextChar=='Q'){
                continueModify=false;
                break;
            }
            cin.ignore(1000,'\n');
            cout<<"请输入正确的索引!"<<endl;
        }
        if(!continueModify){
            continue;
        }
        if(elementIndex>length || elementIndex<0){
            cout<<"输入的索引超出范围!"<<endl;
            continue;
        }
        cout<<"输入元素值:";
        while(!(cin>>arr[elementIndex])){
            cin.clear();
            char nextChar=cin.get();
            if(nextChar=='q' || nextChar=='Q'){
                continueModify=false;
                break;
            }
            cin.ignore(1000,'\n');
            cout<<"请输入正确的数值!"<<endl;
        }
    }
}

template <typename T>
void displayArr(const T arr[],int length){
    for(int i=0;i<length;i++){
        cout<<arr[i]<<'\t';
    }
    cout<<endl;
}

下面是报错的内容
D:\QTproject\DayStudy\main.cpp:28: error: undefined reference to `int fillArr(float*, int)'

D:\QTproject\DayStudy\main.cpp:31: error: undefined reference to `void modifyArr(float*, int)'

D:\QTproject\DayStudy\main.cpp:34: error: undefined reference to `void displayArr(float const*, int)'

collect2.exe:-1: error: error: ld returned 1 exit status

真是吃饱撑的了,你又不是定义类,不用把声明和定义分开,分离调试是很麻烦的一件事,你把.cpp里的内容全部剪切到.h里面就可以了,你可以看看stl里全是在头文件里直接声明加定义,如果你非要这样写的话你可以去研究一下外部模板函数,当然你这种方法用在非模板函数里是没问题的,因为模板函数要实例化,想深入自己百度

int fillArr(T [],int) 的实现在另一个cpp
所以头文件里
int fillArr(T [],int);
应该加上extern
extern int fillArr(T [],int);

谢谢,我后来查了一下,确实是把模板定义放到头文件就好了,我当成常规函数在弄了.