蜗牛奔月球 2016-09-28 14:38 采纳率: 0%
浏览 1050

vs2013实现顺序线性表:fatal error LNK1120:

SqList.h头文件

 #define DEFAULT_SIZE 100
#include<iostream>
template<class ElemType>
class SqList
{
protected:
    int count;
    int maxSize;
    ElemType *elems;
public:
    SqList(int size = DEFAULT_SIZE);
    virtual ~SqList();
    int Length() const;
    bool Empty() const;
    void Clear();
    void Traverse(void(*visit)(const ElemType &))const;
    bool GetElem(int position, ElemType &e) const;
    bool SetElem(int position, const ElemType &e);
    bool Delete(int position, ElemType &e);
    bool Insert(int position, const ElemType &e);
    SqList(const SqList<ElemType> &copy);  //复制构造函数
    SqList<ElemType>& operator=(const SqList<ElemType>& copy);
    void Show();
};
template<class ElemType>
void Difference(const SqList<ElemType> &la, const SqList<ElemType> &lb, SqList<ElemType> &lc);

cpp实现文件

 #include "SqList.h"

template<class ElemType>
SqList<ElemType>::SqList(int size)
{
    maxSize = size;
    elems = new ElemType[maxsize];
    count = 0;
}

template<class ElemType>
SqList<ElemType>::~SqList()
{
    delete[] elems;
}

template<class ElemType>
int SqList<ElemType>::Length()const
{
    return count;
}

template<class ElemType>
bool SqList<ElemType>::Empty() const
{
    return count == 0;
}

template<class ElemType>
void SqList<ElemType>::Clear()
{
    count = 0;
}

template<class ElemType>
void SqList<ElemType>::Traverse(void(*visit)(const ElemType &))const
{
    for (int pos = 1; pos <= count; pos++)
        (*void)(elems[pos - 1]);
}

template<class ElemType>
bool SqList<ElemType>::GetElem(int position, ElemType &e)const
{
    if (position<1 || position>count)
    {
        return false;
    }
    else
    {
        e = elems[position - 1];
        return true;
    }
}

template<class ElemType>
bool SqList<ElemType>::SetElem(int position, const ElemType &e)
{
    if (position<1 || position>count)
    {
        return false;
    }
    else
    {
        elems[position - 1] = e;
        return true;
    }
}

template<class ElemType>
bool SqList<ElemType>::Insert(int position, const ElemType &e)
{
    if (count == maxSize)
        return false;
    else if (position<1 || position>count + 1)
        return false;
    else
    {
        count++;
        for (int i = count; i >= position ; i--)     //count先进行自加运算,所以在末尾处插入新值没有bug;
        {
            elems[i] = elems[i-1];
        }
        elems[position-1] = e;
        return true;
    }
}

template<class ElemType>
bool SqList<ElemType>::Delete(int position, ElemType &e)
{
    if (position<1 || position>count)
        return false;
    else
    {
        GetElem(position, e);
        for (int pos = position; pos <count; pos++)
        {
            elems[pos - 1] = elems[pos];
        }
        count--;
        return true;
    }
}

template<class ElemType>
SqList<ElemType>::SqList(const SqList<ElemType> &copy)
{
    maxSize = copy.maxSize;
    elems = new ElemType[maxSize];
    count = copy.count;

    for (int i = 0; i <= count - 1; i++)
    {
        elems[i] = copy.elems[i];
    }
}

template<class ElemType>
SqList<ElemType>& SqList<ElemType>::operator=(const SqList<ElemType>& copy)
{
    if (&copy != this)
    {
        maxSize = copy.maxSize;
        if (elems != NULL) delete []elems;
        elems = new ElemType[maxSize];
        count = copy.count;

        for (int i = 0; i < count; i++)
        {
            elems[i] = copy.elems[i];
        }
        return true;
    }
}
template<class ElemType>
void SqList<ElemType>::Show()
{
    for (int i = 0; i < count; i++)
    {
        cout << elems[i] << " ";
    }
    cout << endl;
}

template<class ElemType>
void  Difference(const SqList<ElemType> &la,const SqList<ElemType> &lb, SqList<ElemType> &lc)
{
    ElemType aelem, belem;
    bool isExist = false;
    lc.Clear();
    for (int apos = 1; apos <= la.Length(); apos++)
    {
        la.GetElem(apos, aelem);
        isExist = false;
        for (int bpos = 1; bpos <= lb.Length(); bpos++)
        {
            lb.GetElem(bpos, belem);
            if (aelem == belem)
            {
                isExist = true;
                break;
            }
        }
        if (!isExist)
        {
            lc.Insert(lc.Length() + 1, aelem);
        }
    }
}

下面是编译出现的问题:
1>------ 已启动生成: 项目: 头文件, 配置: Debug Win32 ------
1> SqList.cpp
1>测试.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall SqList::SqList(int)" (??0?$SqList@H@@QAE@H@Z),该符号在函数 _main 中被引用
1>测试.obj : error LNK2019: 无法解析的外部符号 "public: virtual __thiscall SqList::~SqList(void)" (??1?$SqList@H@@UAE@XZ),该符号在函数 _main 中被引用
1>测试.obj : error LNK2019: 无法解析的外部符号 "public: bool __thiscall SqList::Insert(int,int const &)" (?Insert@?$SqList@H@@QAE_NHABH@Z),该符号在函数 _main 中被引用
1>测试.obj : error LNK2019: 无法解析的外部符号 "public: void __thiscall SqList::Show(void)" (?Show@?$SqList@H@@QAEXXZ),该符号在函数 _main 中被引用
1>C:\Users\Park\Desktop\数据结构笔记\绪论\头文件\Debug\头文件.exe : fatal error LNK1120: 4 个无法解析的外部命令
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-09-28 15:29
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog