std::vector crash using with DLL? 
Author Message
 std::vector crash using with DLL?

As a guess I would say that you are not deleting the MyClass objects when
you clear the vector.
Objects within vectors are deleted via their destructors when the vector is
'clear'ed but
pointers are not.

Try:-

THEDLL_API void ClearVector(vector<CMyClass *> &vect)
{
    CMyClass *pItem = NULL;
    while(!vect.empty())
    {
        pItem = vect.back();
        delete pItem;
        vect.pop_back();
    }

Quote:
}

and the calling code would be

 vector<CMyClass *> vect;
 AddToVector(vect);
 printf("The string from the vector is %s\n", vect[0]->GetString());
 ClearVector(vect);
 printf("Vector cleared\n");

Rod Paterson


Quote:
> I am having a problem using std::vector with DLLs.

> I have attached a very simple VC6 workspace which illustates the problem.
> It is a console app and a DLL which work toether to produce a crash.   It
> works like this:

> The DLL exports an object called CMyClass, and a function which will add
> pointers to CMyClass to a

> std::vector<CMyClass *>

> I create a vector<CMyClass *> in the application, and then call the
> aforementioned DLL function.  when the vector is destroyed, I get the
crash.

> What am I doing wrong?  Any help much appreciated!!!!

> -Mike



Fri, 10 May 2002 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. export classes using std namespace (ex std::vector) in a DLL

2. using std::string and vector in DLL exported class

3. using std::vector and iterator objects

4. Strange behavior of std:vector used on custom data structure

5. Using containers other than std::vector under VC++5

6. std::vector avoiding using placement allocation ??

7. bug: VS7.0 (6.0) C++ std::auto_ptr conflict with std::vector

8. std::vector passed to DLL class never arrives???

9. Warnings for std::vector<std::string>

10. typedef std::vector<std::string> Vector_String

11. std::list, std::vector, push_back() and associated ::iterator validity

12. passing std::vector to a DLL by reference

 

 
Powered by phpBB® Forum Software