我有一个map<key_t, struct tr_n_t*> nodeTable并且我正在尝试执行nodeTable[a] = someNodewhere ais of typetypedef long key_t和someNodeis of type o_t*。
在 stl_function.h 的执行中,我在以下点遇到分段错误:
/// One of the @link comparison_functors comparison functors@endlink.
template<typename _Tp>
struct less : public binary_function<_Tp, _Tp, bool>
{
bool
operator()(const _Tp& __x, const _Tp& __y) const
{ return __x < __y; }
};
源代码:
#include <stdio.h>
#include <stdlib.h>
#include <map>
using namespace std;
typedef long key_t;
typedef struct tr_n_t {
key_t key;
map<key_t, struct tr_n_t *> nodeTable;
} o_t;
int main() {
o_t *o = (o_t *) malloc(sizeof(o_t));
o->nodeTable[1] = o;
return 0;
}
我没有正确使用地图吗?