将自定义类型插入STL映射的问题 [英] Problem with inserting custom types into STL map

查看:72
本文介绍了将自定义类型插入STL映射的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,这是我的问题:


我有一张地图:


typedef map< string,bfdb_recordBFDB;


其中:


typedef struct

{

size_t seq_no;

StdBloomFilter bf;

} bfdb_record;


其中:


class StdBloomFilter:public BloomFilter
{

私人:

vector< bool__filter;

size_t __size;

public:

StdBloomFilter():__ filter(0),__ size(0){};

StdBloomFilter(size_t _size):__ filter(_size),_ _ _ _ _ _ _ _ _ _ _ <

StdBloomFilter(const StdBloomFilter& _source);


virtual~StdBloomFilter(){};


运算符CountingBloomFilter( );

StdBloomFilter& operator =(const StdBloomFilter&);


void set(size_t _pos);

bool test(size_t _pos)const;


void clear();

size_t size()const;

void merge(const StdBloomFilter& _source);


string to_string();

};


现在我想在我的地图中插入结构:


__db.insert(make_pair(_id,_ info));



__db [_id] = _info;



__db.insert(BFDB :: value_type(_id,_ info));


我收到运行时错误:


8 [主要] LE 2560 _cygtls :: handle_exceptions:异常:

STATUS_ACCESS_VIOLATION

985 [main] LE 2560 open_stackdumpfile:将堆栈跟踪转储到

LE.exe.stackdump


缺少StdBloomFilter中的内容。如果我将bfdb_record结构中的bf更改为int类型,那么一切正常,但这不是我需要的b
需要!!!


请帮助

Hello, this is my problem:

I have a map:

typedef map<string, bfdb_recordBFDB;

where:

typedef struct
{
size_t seq_no;
StdBloomFilter bf;
} bfdb_record;

where:

class StdBloomFilter : public BloomFilter
{
private:
vector<bool__filter;
size_t __size;
public:
StdBloomFilter():__filter(0),__size(0){};
StdBloomFilter(size_t _size): __filter(_size), __size(_size) {};
StdBloomFilter(const StdBloomFilter& _source);

virtual ~StdBloomFilter(){};

operator CountingBloomFilter();
StdBloomFilter& operator=(const StdBloomFilter&);

void set(size_t _pos);
bool test(size_t _pos) const;

void clear();
size_t size() const;
void merge(const StdBloomFilter& _source);

string to_string();
};

now I want to insert structure into my map:

__db.insert(make_pair(_id,_info));
or
__db[_id] = _info;
or
__db.insert(BFDB::value_type(_id, _info));

I get a runtime error:

8 [main] LE 2560 _cygtls::handle_exceptions: Exception:
STATUS_ACCESS_VIOLATION
985 [main] LE 2560 open_stackdumpfile: Dumping stack trace to
LE.exe.stackdump

Is something in StdBloomFilter missing. If I change bf to int type in
the bfdb_record struct then everything works, but that is not what I
need!!!

Please help

推荐答案

ua * ***@gmail.com 写道:

您好,这是我的问题:


我有地图:


typedef map< string,bfdb_recordBFDB;


其中:


typedef struct

{

size_t seq_no;

StdBloomFilter bf;

} bfdb_record;
Hello, this is my problem:

I have a map:

typedef map<string, bfdb_recordBFDB;

where:

typedef struct
{
size_t seq_no;
StdBloomFilter bf;
} bfdb_record;



那是C.你想要


struct bfdb_record

{

size_t seq_no;

StdBloomFilter bf;

};


你确定每次要复制整个StdBloomFilter对象

你做插入吗?

That''s C. You want

struct bfdb_record
{
size_t seq_no;
StdBloomFilter bf;
};

Are you sure you want to copy the entire StdBloomFilter object each time
you do an insert?


其中:


class StdBloomFilter: public BloomFilter

{

private:

vector< bool__filter;

size_t __size;
where:

class StdBloomFilter : public BloomFilter
{
private:
vector<bool__filter;
size_t __size;



这些都是非法名称,任何以双下划线开头的东西都是

保留。

Those are illegal names, anything starting with double underscore is
reserved.


>

现在我想在我的地图中插入结构:


__db.insert(make_pair(_id,_ info));



__db [_id] = _info;



__db.insert(BFDB :: value_type(_id,_info ));


我收到运行时错误:
>
now I want to insert structure into my map:

__db.insert(make_pair(_id,_info));
or
__db[_id] = _info;
or
__db.insert(BFDB::value_type(_id, _info));

I get a runtime error:



你的StdBloomFilter复制构造函数有什么作用?


-

Ian Collins。

What does your StdBloomFilter copy constructor do?

--
Ian Collins.


StdBloomFilter& StdBloomFilter :: operator =(const StdBloomFilter&

_source)

{

this-> __ size = _source .__ size;

this-> __ filter = _source .__ filter;

}


该怎么办?这些都没有指针。这些应该是价值的副本

,对吗?它没有用,所以我添加了这个虚拟副本

构造函数,但它仍然不起作用。

StdBloomFilter& StdBloomFilter::operator=(const StdBloomFilter&
_source)
{
this->__size=_source.__size;
this->__filter =_source.__filter;
}

And what should it do? These are no pointers. These should be copies
by value, right? It was not working, so I added this dummy copy
constructor, but it still does not work.


ua **** @ gmail.com 写道:


请引用相应的上下文,这篇文章没有任何意义。
ua****@gmail.com wrote:

Please quote the appropriate context, this post makes no sense on its own.

StdBloomFilter& StdBloomFilter :: operator =(const StdBloomFilter&

_source)

{

this-> __ size = _source .__ size;

this-> __ filter = _source .__ filter;
StdBloomFilter& StdBloomFilter::operator=(const StdBloomFilter&
_source)
{
this->__size=_source.__size;
this->__filter =_source.__filter;



您真的应该摆脱这些非法名称。

You realy should get rid of these illegal names.


}

这应该怎么办?这些都没有指针。这些应该是价值的副本

,对吗?它没有用,所以我添加了这个虚拟副本

构造函数,但它仍然不起作用。
}

And what should it do? These are no pointers. These should be copies
by value, right? It was not working, so I added this dummy copy
constructor, but it still does not work.



在调试器下运行代码并看看它在做什么。你不会在基类上显示

,所以问题可能就在那里。


-

Ian柯林斯。

Run you code under a debugger and see what it is doing. You don''t show
the base class, so the problem may well be in there.

--
Ian Collins.


这篇关于将自定义类型插入STL映射的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆