Archived

This topic is now archived and is closed to further replies.

VC++ .NET & STL

This topic is 5575 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there I would like to find out if you have to do/add something special to make use of STL in .NET, with my previous project in VC++ 6.0 I had no problem using STL but now with that I moved my project to VC++ .Net I get strange copulation errors with some of the STL containers. here is an idea how my errors look like e:\Dev\Plastic\object_handler.h(62): error C2664: ''std::vector >:ush_back'' : cannot convert parameter 1 from ''CObjectBase *'' to ''const CObjectBase &'' e:\Dev\Plastic\object_handler.h(67): error C2440: ''return'' : cannot convert from ''std::vector<_Ty,_Ax> *'' to ''std::vector<_Ty,_Ax> *'' with [ _Ty=CObjectBase, _Ax=std::allocator ] and [ _Ty=CObjectBase *, _Ax=std::allocator ] Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast this code worked in compiled successfully in VC++ 6.0 any ideas http://www.freewebz.com/plastic/

Share this post


Link to post
Share on other sites
Show us the code which causes these errors.

What you''ve got is a vector which looks like vector<CObjectBase> but you''re trying to use it with pointers to CObjectBase. Change the declaration to vector<CObjectBase *> and see how that goes.

If I had my way, I''d have all of you shot!


codeka.com - Just click it.

Share this post


Link to post
Share on other sites
//-------------
inline void CObjectBase::vAttachChild(CObjectBase* child)
{
assert(child);
child->vSetParent(this);
m_pChildList.push_back(child);
}

//-------------
inline vector *CObjectBase:GetChildList()
{
return &m_pChildList;
}

hope this helps

here is the basic part of the class

//---------
class CObjectBase
{
protected:
vector m_pChildList;
CObjectBase* m_pParentObject;

bool m_bEnabled;
bool m_bNoDelete;
bool m_bStatic;

public:
void vSetParent(CObjectBase* parent);
void vAttachChild(CObjectBase* child);
vector *pGetChildList();
//bla
//bla
};

http://www.freewebz.com/plastic/

Share this post


Link to post
Share on other sites
The problem is exactly what Dean said it was. You''re trying to push back a CObjectBase* into a CObjectBase vector (notice not a pointer). You either need to dereference it, using the * operator, or change your vector to a vector. The latter will allow you to store pointers to derived classes.


Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites
"I swear, honey, I never get copulation errors like this! Just give me a minute to reboot myself."


Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites