C ++对`vtable的未定义引用

2024-03-06

我的问题与我发布的另一个问题有所不同。我一开始使用多个文件,并决定暂时将其全部放入一个 main.cpp 文件中,以使其正常工作。

主要.cpp:

#include <iostream>
using namespace std;

class arrayListType {
    public:
        bool isEmpty() ;
        bool isFull() ;
        int listSize() ;
        int maxListSize() ;
        void print() ;
        bool isItemAtEqual(int location, int item) ;
        virtual void insertAt(int location, int insertItem) = 0;
        virtual void insertEnd(int insertItem) = 0;
        void removeAt(int location);
        void retrieveAt(int location, int& retItem) ;
        virtual void replaceAt(int location, int repItem) = 0;
        void clearList();
        virtual int seqSearch(int searchItem) const  = 0;
        virtual void remove(int removeItem) = 0;
        arrayListType (int size = 100);
        arrayListType ( arrayListType& otherList);
        virtual ~arrayListType();
    protected:
        int *list;
        int length;
        int maxSize;
};


bool arrayListType::isEmpty()  {
    return (length == 0);
}
bool arrayListType::isFull()  {
    return (length == maxSize);
}
int arrayListType::listSize()  {
    return length;
}
int arrayListType::maxListSize()  {
    return maxSize;
}
void arrayListType::print()  {
    for (int i = 0; i < length; i++)
        cout << list[i] << " ";
    cout << endl;
}
bool arrayListType::isItemAtEqual(int location, int item)  {
    if (location < 0 || location >= length) {
        cout << "The location of the item to be compared is out range." << endl;
        return false;
    }
    else
        return(list[location] == item);
}


void arrayListType::removeAt(int location) {
    if (location < 0 || location >= length){
        cout << "The location of the item to be removed is out of range." << endl;
    }
    else {
        for (int i = location; i < length -1; i++)
            list[i] = list[i+1];
        length--;
    }
}
void arrayListType::retrieveAt(int location, int& retItem)  {
    if (location < 0 || location >= length) {
        cout << "The location of the item to be retrieved is out of range." << endl;
    }
    else
        retItem = list[location];
}


void arrayListType::clearList() {
    length = 0;
}


arrayListType::arrayListType (int size) {
    if (size <= 0) {
        cout << "The array size must be positive. Creating an array of the size 100." << endl;
        maxSize = 100;
    }
    else
        maxSize = size;
    length = 0;
    list = new int[maxSize];
}

class orderedArrayListType: public arrayListType {

    public:
        void insertAt(int location, int insertItem);
        void insertEnd(int insertItem);
        void replaceAt(int location, int repItem);
        int seqSearch(int searchItem) const;
        void insert (int insertItem);
        void remove (int removeItem);
        orderedArrayListType (int size = 100);
        ~orderedArrayListType();
    private:
        void quickSort();
};



void orderedArrayListType::quickSort(){
//private function for sorting "list."
//using a "quicksort" method
//addapted from: http://www.algolist.net/Algorithms/Sorting/Quicksort
    if (length == 0) {
        cout << "Cannot sort an ampty list." << endl;
    }
    else {
        int left = 0, right = length;
        int i = left, j = right;
    int tmp;
    int pivot = list[(left + right) / 2];
    /* partition */
    while (i <= j) {
        while (list[i] < pivot)
            i++;
        while (list[j] > pivot)
            j--;
        if (i <= j) {
            tmp = list[i];
            list[i] = list[j];
            list[j] = tmp;
            i++;
            j--;
        }
    };
    /* recursion */
    if (left < j)
        quickSort();
    if (i < right)
        quickSort();
    }
}




void orderedArrayListType::insertAt(int location, int insertItem){

    if (location < 0 || location >= length){
        cout << "The location of the item to be removed "
        << "is out of range." << endl;
    }
    else if(length == maxSize){
        cout << "Cannot insert in a full list." << endl;
    }
    else {
        for (int j = length; j < location; j--){ 
            list[j+1] = list[j]; 
            /* 
            Start at the end of the array and move each item 
            out by one. Coninue until list[j] is at the 
            location, then set the list[location] to the value.
            */  
        }
        list[location] = insertItem;
        length++;
    }
    quickSort();
}

void orderedArrayListType::insertEnd(int insertItem) {

    if (length == maxSize){
        cout << "Cannot insert in a full list." << endl;
    }
    else {
        list[length] = insertItem;
        length++;
    }
    quickSort();
}


void orderedArrayListType::replaceAt(int location, int repItem) {
    if (location < 0 || location >= length){
        cout << "The location of the item to be replaced "
        << "is out of range." << endl;
    }
    else
        list[location] = repItem;
    quickSort();
}

int orderedArrayListType::seqSearch(int searchItem) const {

    int loc;
    bool found = false;
    loc = 0;
    while (loc < length && !found) {
        if (list[loc] == searchItem)
            found = true;
        else
            loc++;
    }
    if (found)
        return loc;
    else
        return -1;
}


void orderedArrayListType::insert (int insertItem){
    if (length == 0){
        list[length++] = insertItem;
    }
    else if (length == maxSize){
        cout << "Cannot insert in a full list." << endl;
    }
    else {
        int loc;
        bool found = false;
        for (loc= 0; loc < length; loc++){
            if (list[loc] >= insertItem){
                found = true;
                break;
            }
        }
        for (int i = length; i > loc; i--) {
            list[i] = list[i-1];
        }
        list[loc] = insertItem;
        length++;
    }
    quickSort();
}
void orderedArrayListType::remove (int removeItem) {

    int loc;

    if (length == 0)
        cout << "Cannot Delete from an ampty list." << endl;
    else {
        loc = seqSearch(removeItem);
        if (loc != -1)
            removeAt(loc);
        else
            cout << "The item to be deleted is not in the list." << endl;
    }
}


orderedArrayListType::orderedArrayListType (int size)
    :arrayListType(size){
}





int main() {

//  orderedArrayList intlist(25);
//  orderedArrayListType intList = new orderedArrayListType(25);
}

确切的错误信息:

/tmp/ccdTFaE0.o:功能中arrayListType::arrayListType(int)': main3.cpp:(.text+0x25c): undefined reference to虚拟表为 数组列表类型' /tmp/ccdTFaE0.o:(.rodata._ZTV20orderedArrayListType[虚表 有序数组列表类型]+0
x38): 未定义的引用orderedArrayListType::~orderedArrayListType()' /tmp/ccdTFaE0.o:(.rodata._ZTV20orderedArrayListType[vtable for orderedArrayListType]+0
x40): undefined reference to
orderedArrayListType::~orderedArrayListType()' /tmp/ccdTFaE0.o:(.rodata._ZTI20orderedArrayListType[类型信息 有序数组列表类型]
+0x10): 对 `typeinfo for arrayListType' 的未定义引用collect2: ld 返回 1 退出状态

tldr;

#include <iostream>
using namespace std;

class arrayListType {
    public:
        bool isEmpty() const;
                ...
                arrayListType (int size = 100);
        arrayListType ( arrayListType& otherList);
        virtual ~arrayListType();
    protected:
        int *list;
        int length;
        int maxSize;
};


//definitions 
bool arrayListType::isEmpty()  {
    return (length == 0);
}

class orderedArrayListType: public arrayListType {

    public:
        void insertAt(int location, int insertItem);
        ...
        orderedArrayListType (int size = 100);
        ~orderedArrayListType();
    private:
        void quickSort();
};



void orderedArrayListType::quickSort(){
 ...
 }




void orderedArrayListType::insertAt(int location, int insertItem){

       ....     

    quickSort();
}

   orderedArrayListType::orderedArrayListType (int size)
    :arrayListType(size){
}


int main() {

    orderedArrayList intlist(25);
//  orderedArrayListType intList = new orderedArrayListType(25);
}

您缺少析构函数定义:

arrayListType::~arrayListType() { }

orderedArrayListType::~orderedArrayListType() { }

链接器错误通常不是很有用。但是,当您声明但不定义析构函数时,通常会生成这个确切的错误。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

C ++对`vtable的未定义引用 的相关文章

  • 调用许多网络服务的最佳方式?

    我有 30 家子公司 每家都实施了他们的 Web 服务 使用不同的技术 我需要实现一个Web服务来聚合它们 例如 所有子公司的Web服务都有一个名为的Web方法GetUserPoint int nationalCode 我需要实现我的网络服
  • 在 Web 浏览器中禁用 F5 [重复]

    这个问题在这里已经有答案了 可能的重复 禁用浏览器的后退按钮 https stackoverflow com questions 961188 disable browsers back button 如何禁用浏览器上的 F5 刷新 htt
  • std::list::clear 是否会使 std::list::end 迭代器无效?

    检查这个代码 include stdafx h include
  • Nullable 是不可能的,为什么不呢? [复制]

    这个问题在这里已经有答案了 如果这是一个愚蠢的问题 请原谅 我正在尝试更好地理解 Net 中的 Nullable 类型 从我从 Microsoft 源代码 使用 ReSharper 中注意到的内容 我了解到 Nullable 是一个结构 而
  • EventHandler 应该始终用于事件吗?

    我一直在愉快地使用自定义委托类型和通用编写事件Action委托类型 没有真正考虑我在做什么 我有一些很好的扩展助手Action and EventHandler这使我倾向于使用那些预定义的委托类型而不是我自己的委托类型 但除此之外 除了惯例
  • 从另一个 FORM 中取回隐藏的 FORM

    我有两种形式Form1 and Form2 我正在打开Form2 from Form1 on button Click Form2 obj2 new Form2 this Visible false obj2 Show 然后我想回来Form
  • .pdbs 会减慢发布应用程序的速度吗?

    如果 dll 中包含 pdb 程序调试 文件 则行号将出现在引发的任何异常的堆栈跟踪中 这会影响应用程序的性能吗 这个问题与发布与调试 即优化 无关 这是关于拥有 pdb 文件的性能影响 每次抛出异常时都会读取 pdb 文件吗 加载程序集时
  • 在 Mac OS X 上安装 libxml2 时出现问题

    我正在尝试在我的 Mac 操作系统 10 6 4 上安装 libxml2 我实际上正在尝试在 Python 中运行 Scrapy 脚本 这需要我安装 Twisted Zope 现在还需要安装 libxml2 我已经下载了最新版本 2 7 7
  • MSMQ接收和删除

    是否有任何选项可以在读取消息后将其从 MSMQ 中删除 比如 接收 删除可以作为原子操作运行吗 听起来您想查看下一条消息 然后在处理完成后接收它 Message message Queue Peek Queue ReceiveById me
  • Nhibernate:连接表并从其他表获取单列

    我有以下表格 create table Users Id uniqueidentifier primary key InfoId uniqueidentifier not null unique Password nvarchar 255
  • 如何使用 C# 查询远程 MS ACCESS .mdb 数据库

    我正在尝试使用 C 查询 mote MS ACCESS 数据库 mdb 文件 将文件复制到本地计算机时可以成功查询它 我只想远程放置文件 所以我的客户端程序不包含原始数据 static string m path http www xyz
  • 如何在 EF Core 2.1 中定义外键关系

    我的 DAL 使用 EF Core 2 1 这就是我的模型的样子 一名用户只能拥有一种角色 Role entity kind of master public class Role public int RoleId get set pub
  • MSChart 控件中的自定义 X/Y 网格线

    我有一个带有简单 2D 折线图的 C Windows 窗体 我想向其中添加自定义 X 或 Y 轴标记 并绘制自定义网格线 例如 以突出显示的颜色 虚线 我查看了 customLabels 属性 但这似乎覆盖了我仍然想显示的默认网格 这是为了
  • C 与 C++ 中的 JNI 调用不同?

    所以我有以下使用 Java 本机接口的 C 代码 但是我想将其转换为 C 但不知道如何转换 include
  • 在 C++ 代码 gdb 中回溯指针

    我在运行 C 应用程序时遇到段错误 在 gdb 中 它显示我的一个指针位置已损坏 但我在应用程序期间创建了 10 万个这样的对象指针 我怎样才能看到导致崩溃的一个 我可以在 bt 命令中执行任何操作来查看该指针的生命周期吗 谢谢 鲁奇 据我
  • 使用 Unity 在 C# 中发送 http 请求

    如何使用 Unity 在 C 中发送 HTTP GET 和 POST 请求 我想要的是 在post请求中发送json数据 我使用Unity序列化器 所以不需要 新的 我只想在发布数据中传递一个字符串并且能够 将 ContentType 设置
  • 用数组或向量实现多维数组

    我想使用单个数组或向量实现多维数组 可以像通常的多维数组一样访问它 例如 a 1 2 3 我陷入困境的是如何实施 操作员 如果数组的维数为 1 则 a 1 应该返回位于索引 1 处的元素 但是如果维数大于一怎么办 对于嵌套向量 例如 3 维
  • 将日期时间显示为 MM/dd/yyyy HH:mm 格式 C#

    在数据库中 日期时间以 MM dd yyyy HH mm ss 格式存储 但是 我想以 MM dd yyyy HH mm 格式显示日期时间 我通过使用 String Format 进行了尝试 txtCampaignStartDate Tex
  • 不使用放置 new 返回的指针时的 C++ 严格别名

    这可能会导致未定义的行为吗 uint8 t storage 4 We assume storage is properly aligned here int32 t intPtr new void storage int32 t 4 I k
  • 如何在 Razor 编辑视图中显示选中的单选按钮 Asp net core mvc

    尽管 Razor 视图中的 Asp 网络核心代码 model List

随机推荐

  • 数组“__curl_rule_01__”的大小为负数

    我在尝试编译 GIT 时遇到错误 我已经在 Google 和 GIT 源代码问题 错误中搜索了类似的问题 但没有找到任何可以帮助我的内容 最初我收到以下错误 root teemo usr src git make prefix usr in
  • 使用 Swift 3.0 将 JSON 数组解析到服务器

    我正在尝试将 JSON 数组发送到 Web 服务器 我在网上看了几个例子 即 and 使用 Swift 3 0 将 CoreData 保存到 Web 服务器 https stackoverflow com questions 4619996
  • 使用前缀或域的路由

    我正在开发一个平台 该平台允许用户在主网站域的子文件夹中运行自己的网站 或者为其网站映射自定义域 使用自定义域时 每个路由的 URL 结构略有不同 因为它以用户名为前缀 但使用自定义域时 不使用此前缀 有没有一种巧妙的方法可以在我的 Rou
  • 通过递归得出帕斯卡三角形

    有人可以告诉我我当前的代码是否可行吗 我必须使用输入创建帕斯卡三角形 而不使用任何循环 我注定要递归 我花了三天时间来做这个 这是我能想到的最好的输出 def pascal curlvl newlvl tri if curlvl newlv
  • R 中向量的子集()

    我根据以下函数编写了subset 我觉得很方便 ss lt function x subset r lt eval substitute subset data frame x parent frame if is logical r st
  • 将 JSON 解析为 MONGODB 文档

    我是新来的JAVA and MONGODB并且一直在学习尝试并了解这些技术是否能够满足我对产品的要求 我目前陷入无法插入文档 记录 的地步JAVA进入我的MONGODB收藏 我正在使用新的MONGODB version 3 0 到目前为止的
  • 如何在heroku 上托管我的discord.py 机器人?

    我目前正在尝试将我的 Discord 机器人连接到 Heroku 并 24 7 托管它 但我遇到了问题 我将我的机器人上传到 githubhttps github com zemocode flankebot tree master htt
  • 如何更改 .net Web 应用程序中的默认区域性设置?

    我们的 Web 应用程序 net C 使用 amount ToString c 格式化货币金额 显示为几个不同区域的本地化 我们的法裔加拿大用户更喜欢所有金额均采用美国格式 123 456 99 而 fr CA 的默认 Windows 格式
  • Android中如何将日志写入SD卡? [复制]

    这个问题在这里已经有答案了 我的程序在设备中崩溃 我想在我的设备中运行时准确捕获程序的日志 即我想将日志写入我的 SD 卡 直到崩溃为止 我怎样才能实现这个目标 尝试这个 Thread setDefaultUncaughtException
  • 从模块关闭用户窗体

    我正在尝试从模块关闭用户表单 但它不起作用 这是我尝试过的 Sub UpdateSheetButton Dim subStr1 As String Dim subSrrt2 As String Dim tmp As Integer Dim
  • Android Flash 切换按钮崩溃

    应用程序在四种不同的设备上运行良好 但客户端在打开 关闭闪光灯按钮时面临崩溃Xperia z2 主要活动 btnFlash setOnClickListener new OnClickListener Override public voi
  • 需要 Nest REST API 的工作示例而不使用 Firebase API

    我正在努力寻找一个使用普通休息将数据写入 Nest Thermostat API 的工作示例 尝试编写 C 应用程序但无法使用 Firebase 到目前为止发布的多个 Curl 示例不起作用 我有一个有效的 auth token 并且可以毫
  • 为分配/指派问题建立线性规划

    我在线性程序方面遇到了一些麻烦 我已经解决并使用 Excel 但现在我想在 R Python 中执行它 因为我已经达到了 Excel 和求解器的限制 因此 我就这个特定主题寻求帮助 我通过改变 lp assign 函数尝试使用 lPsovl
  • 需要在 web.config 中加密连接字符串和 stmp 信息

    我想在 web config 中保留加密的连接字符串和 stmp 信息 我可以将连接字符串和 SMTP 信息加密存储在 web config 中 并在其中解密和使用吗 OR 我可以加密连接字符串和 SMTP 并保存在 web config
  • Objective-C++ 导入 C++ 类失败,找不到 cassert

    因此 我想公开公开一个 Box2D C 指针 指向我的 cocos2d box2d 项目中的其他 Objective C 类 我在接口中声明了一个方法 getWorld 该方法引用 C 类 b2World 并导入 Box2D h 我的项目中
  • Prisma 部署 Docker 错误“无法连接到服务器”

    这是我已经完成的步骤 prisma init 我在本地 不存在 中为数据库设置了 postgresql 它创建了 3 个文件 datamodel graphql docker compose yml prisma yml docker co
  • 在Databricks(DBFS)中递归列出目录和子目录的文件

    使用python dbutils 如何在Databricks文件系统 DBFS 中递归显示当前目录和子目录的文件 关于 dbutils fs ls 和 fs 魔法命令 的令人惊讶的事情是它似乎不支持任何递归开关 然而 由于 ls 函数返回
  • 如何让VIM在写信时播放打字机声音?

    写了很多之后Windows 上的 Q10 http www baara com q10 我已经习惯了每次按键时发出的打字机声音 至少对我来说 拥有这种声音反馈感觉很棒 另一方面 在 Linux 上 我喜欢用 VIM 编写它 因为它的编辑功能
  • 如何使用 iOS 应用程序中的 X.509 证书数据对 PDF 进行数字签名

    我正在我的应用程序中生成 PDF 我想为通过我的应用程序生成的这些 pdf 提供最好的安全性 我添加了 Apple 提供的默认安全选项 例如所有者密码 允许复制 允许打印等 但我想添加我的证书信息或将其称为使用自定义证书 X 509 证书
  • C ++对`vtable的未定义引用

    我的问题与我发布的另一个问题有所不同 我一开始使用多个文件 并决定暂时将其全部放入一个 main cpp 文件中 以使其正常工作 主要 cpp include