【发布时间】:2011-03-07 02:39:00
【问题描述】:
问题是,我不是(知道尝试使用 beatle::beatle 的任何默认构造函数
错误:
1> ecosystem.cpp
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\map(172): error C2512: 'beatle::beatle' : no appropriate default constructor available
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\map(165) : while compiling class template member function 'beatle &std::map<_Kty,_Ty>::operator [](int &&)'
1> with
1> [
1> _Kty=tokenID,
1> _Ty=beatle
1> ]
1> c:\users\zak\documents\visual studio 2010\projects\ascii_sivvure\ascii_sivvure\ecosystem.h(22) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled
1> with
1> [
1> _Kty=tokenID,
1> _Ty=beatle
1> ]
去掉不相关内容的代码:
标题:
typedef std::map<tokenID,beatle> Beatles;
class ecosystem
{
private:
line 22: Beatles m_Beatles;
};
来源:
ecosystem::ecosystem(): m_output( output() )
{
Beatles m_Beatles;
}
void ecosystem::populate()
{
if (m_isMatingSeason && ( random(0,1000) < rateMATING ) )
{
beatle babyBeatle = breed();
m_Beatles[babyBeatle.getTokenID()] = babyBeatle;
m_field.occupy(babyBeatle.getTokenID(), babyBeatle.getLocation() );
}
}
我已经尝试使用不同的组合尝试正确定义/声明maps 几个小时。有一次智能感知开始说它想要指向对象的指针:
m_Beatles[babyBeatle.getTokenID()] = babyBeatle;
这让我走上了一条悲伤的道路。
这一切都发生在我第一次(希望是最后一次)重构狂潮之后,距离我能够编译已经一个多星期了......我可能有 40 个小时试图让它再次工作。
【问题讨论】:
标签: c++ templates constructor