任何机构都可以帮我解决这个问题。我有一个类在其地图容器Comm
中存储另一个类的元素:Info
#include<map>
using namespace std;
class En
{
};
class Info
{
public:
const En * en;
bool read;
bool write;
bool done;
Info(
En * en_,
bool read_,
bool write_,
bool done_
)
:
en(en_),
read(read_),
write(write_),
done(done_)
{}
Info(const Info& info_)
:
en(info_.en),
read(info_.read),
write(info_.write),
done(info_.done)
{}
};
class Comm
{
std::map<const En*,Info> subscriptionList;
public:
void subscribeEn(Info value)
{
//none of the below works
// subscriptionList[value.en] = Info(value);
subscriptionList[value.en] = value;
}
};
int main()
{
// En * en;
// bool read;
// bool write;
// bool Done;
// Comm comm;
// Info Info_(en,read,write,Done);
// comm.subscribeEn(Info_);
// return 1;
}
但我在编译时收到以下错误:
In file included from /usr/include/c++/4.7/map:61:0,
from test.cpp:1:
/usr/include/c++/4.7/bits/stl_map.h: In instantiation of ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = const En*; _Tp = Info; _Compare = std::less<const En*>; _Alloc = std::allocator<std::pair<const En* const, Info> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = Info; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = const En*]’:
test.cpp:47:27: required from here
/usr/include/c++/4.7/bits/stl_map.h:458:11: error: no matching function for call to ‘Info::Info()’
/usr/include/c++/4.7/bits/stl_map.h:458:11: note: candidates are:
test.cpp:28:2: note: Info::Info(const Info&)
test.cpp:28:2: note: candidate expects 1 argument, 0 provided
test.cpp:15:2: note: Info::Info(En*, bool, bool, bool)
test.cpp:15:2: note: candidate expects 4 arguments, 0 provided
如果你让我知道我为什么会得到这个以及如何解决它,我将不胜感激。谢谢你