Reputation: 3
I recently just heard of the new unique_ptr in C++11 and wanted to try it.
I changed this code :
void CreateDummySpell(uint32 id)
{
const char * name = "Dummy Trigger";
SpellEntry * sp = new SpellEntry;
memset(sp, 0, sizeof(SpellEntry));
sp->Id = id;
sp->Attributes = 384;
sp->AttributesEx = 268435456;
sp->AttributesExB = 4;
sp->CastingTimeIndex=1;
sp->procChance=75;
sp->rangeIndex=13;
sp->EquippedItemClass=uint32(-1);
sp->Effect[0]=3;
sp->EffectImplicitTargetA[0]=25;
sp->NameHash=crc32((const unsigned char*)name, (unsigned int)strlen(name));
sp->dmg_multiplier[0]=1.0f;
sp->StanceBarOrder=-1;
dbcSpell.SetRow(id,sp);
sWorld.dummyspells.push_back(sp);
}
to this
void CreateDummySpell(uint32 id)
{
const char * name = "Dummy Trigger";
// SpellEntry * sp = new SpellEntry;
std::unique_ptr<SpellEntry> sp(new SpellEntry);
memset(sp, 0, sizeof(SpellEntry));
sp->Id = id;
sp->Attributes = 384;
sp->AttributesEx = 268435456;
sp->AttributesExB = 4;
sp->CastingTimeIndex=1;
sp->procChance=75;
sp->rangeIndex=13;
sp->EquippedItemClass=uint32(-1);
sp->Effect[0]=3;
sp->EffectImplicitTargetA[0]=25;
sp->NameHash=crc32((const unsigned char*)name, (unsigned int)strlen(name));
sp->dmg_multiplier[0]=1.0f;
sp->StanceBarOrder=-1;
dbcSpell.SetRow(id,sp);
sWorld.dummyspells.push_back(sp);
}
Now I'm getting this error :
error C2664: 'void *memset(void *,int,size_t)': cannot convert argument 1 from 'std::unique_ptr<SpellEntry,std::default_delete<_Ty>>' to 'void *'
2> with
2> [
2> _Ty=SpellEntry
2> ]
2> ..\..\src\arcemu-world\SpellFixes.cpp(29): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
2>..\..\src\arcemu-world\SpellFixes.cpp(43): error C2664: 'void DBCStorage<SpellEntry>::SetRow(uint32,T *)': cannot convert argument 2 from 'std::unique_ptr<SpellEntry,std::default_delete<_Ty>>' to 'SpellEntry *'
2> with
2> [
2> T=SpellEntry
2> ]
2> and
2> [
2> _Ty=SpellEntry
2> ]
2> ..\..\src\arcemu-world\SpellFixes.cpp(43): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
2>..\..\src\arcemu-world\SpellFixes.cpp(44): error C2664: 'void std::list<SpellEntry *,std::allocator<_Kty>>::push_back(const _Ty &)': cannot convert argument 1 from 'std::unique_ptr<SpellEntry,std::default_delete<_Ty>>' to 'SpellEntry *&&'
2> with
2> [
2> _Kty=SpellEntry *
2> , _Ty=SpellEntry *
2> ]
2> and
2> [
2> _Ty=SpellEntry
2> ]
2> ..\..\src\arcemu-world\SpellFixes.cpp(44): note: Reason: cannot convert from 'std::unique_ptr<SpellEntry,std::default_delete<_Ty>>' to 'SpellEntry *'
2> with
2> [
2> _Ty=SpellEntry
2> ]
2> ..\..\src\arcemu-world\SpellFixes.cpp(44): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
It seems like I can pass sp as arguments. How do you pass sp as argument using unique_ptr smart pointers?
Thanks in advance.
too short message...
Upvotes: 0
Views: 1852