诡异的错误,malloc 出现问题
好无头绪的错误
////////index.h
#pragma once
using namespace std;
class Idx
{
public:
Idx();
~Idx();
};
////////index.cpp
#include "index.h"
Idx::Idx() {}
Idx::~Idx(){}
////////main.cpp
#include "index.h"
using namespace std;
typedef struct _index_node
{
shared_ptr<Idx> idx;
} IndexNode;
int main(int argc, char *argv[]) {
IndexNode *t1 = (IndexNode *)malloc(sizeof(IndexNode));
t1->idx = nullptr;
IndexNode *t3 = (IndexNode *)malloc(sizeof(IndexNode));
exit(0);
}
代码运行到IndexNode *t3 = (IndexNode *)malloc(sizeof(IndexNode));这行是报错
(gdb) bt
#0 _int_malloc (av=av@entry=0x7ffff4f95760 <main_arena>, bytes=bytes@entry=16)
at malloc.c:3415
#1 0x00007ffff4c5484c in __GI___libc_malloc (bytes=16) at malloc.c:2899
#2 0x000000000041e408 in main (argc=4, argv=0x7fffffffe378)
at /mnt/hgfs/mydev/trade/backtest/main.cpp:42
同时gdb 调试时,*p t1,出现如下waring
(gdb) p *t1
$2 = {idx = warning: can't find linker symbol for virtual table for `std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>' value
warning: can't find linker symbol for virtual table for `std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>' value
std::shared_ptr (count -184985656, weak 32766) 0x7ffff4f957d8 <main_arena+120>}
彻底傻了有谁能帮我