相关疑难解决方法(0)

未解析的外部符号 - 模板类

可能重复:
C++模板,链接错误

我正在尝试实现选择排序,但我不断收到错误(打印在下面).在我看来,我的所有包含和模板都正确完成.有人可以向我解释这个错误的原因以及调试此类错误的一般方法.通常情况下会出现包含或模板问题,但偶尔会出现在我不知道错误的情况下.谢谢.

错误LNK2019:函数_main中引用的未解析的外部符号"public:void __thiscall Selection :: SelectionSort(int*const,int)"(?SelectionSort @?$ Selection @ H @@ QAEXQAHH @ Z)

TEST.CPP

#include <iostream>
#include "SelectionSort.h"
using namespace std;

void main()
{
    int ar[] = {1,2,3,4,5};
    Selection<int> s;
    s.SelectionSort(ar,5);

    for(int i = 0; i < 5; i++)
    {

        cout << "\nstudent number " << i + 1<< " grade " << ar[i];
    }
}
Run Code Online (Sandbox Code Playgroud)

SelcectionSort.h

template<class ItemType>
class Selection
{
public:
    void SelectionSort(ItemType[], int);
private:
    int MinIndex(ItemType[], int, int);
    void Swap(ItemType& , ItemType&);
};
Run Code Online (Sandbox Code Playgroud)

SelectionSort.cpp …

c++ templates

2
推荐指数
1
解决办法
6364
查看次数

标签 统计

c++ ×1

templates ×1