【学习笔记】各种错误记录

stack_overflow

递归次数过多爆栈辣

heap-buffer-overflow

内存是否存在非法访问

默认构造函数

call to implicitly-deleted default constructor of ‘unordered_set<vector >’

unordered_set基于hashtable实现,而我所使用的key_value是vector<int>没有hash键值

这篇博客这篇博客展示了如何自己写hash函数重载

struct hashfunc
{
    template<typename T, typename U>
    size_t operator() (const pair<T, U> &i) const
    {
        return hash<T>()(i.first) ^ hash<U>()(i.second);
    }
};
unordered_map< pair<int, int>, int , hashfunc > mp;
struct MyKeyHashHasher
{
	size_t operator()(const MyKey &k) const noexcept
	{
		return std::hash<int>{}(k.key);
	}
};

duplicate symbols for architecture arm64

在这里插入图片描述
一个文件里的函数太多了,打算拆一部分到另一个.cpp,结果就报错。错因是函数或者全局变量重定义了,但是我注释掉所有的函数之后,只剩下头上的这些,大家来看看哪里出问题了hhhh

#include "mesh.h"

#include <iostream>
#include <fstream>

#include <QFileInfo>
#include <QString>

#define TINYOBJLOADER_IMPLEMENTATION
#include "util/tiny_obj_loader.h"

using namespace Eigen;
using namespace std;

好的揭晓答案,是#define TINYOBJLOADER_IMPLEMENTATION 。

This directive causes the implementation of TinyObjLoader to be included wherever this line is processed. If mesh.cpp or another file including mesh.h (or directly including util/tiny_obj_loader.h) also has or indirectly includes this directive, it will lead to multiple definitions of TinyObjLoader’s implementation, hence the duplicate symbols error. – from ChatGPT

只把这两行包含在用到obj loader的源文件里就解决啦。

map

    // Create new faces.
    Face* face_cma = new Face(F.size());
    cout << "F " << F.size() << endl;
    F.insert({F.size(), face_cma});
    Face* face_cmd = new Face(F.size());
    cout << "F " << F.size() << endl;
    F.insert({F.size(), face_cmd});
    Face* face_amb = new Face(F.size());
    cout << "F " << F.size() << endl;
    F.insert({F.size(), face_amb});
    Face* face_dmb = new Face(F.size());
    cout << "F " << F.size() << endl;
    F.insert({F.size(), face_dmb});

发现原来F.size()不能作为key插入,因为

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值