Hello just curious, I know that i'm supposed to use new in c++ but decided to experiemnt with malloc.
Can you explain to me why the following code crashes and what is the reason. I was under the impression that the size of vector is fixed as it just stores a pointer to an dyanamic allocated array which holds the elements.
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector< string > * u = (vector< string >*) malloc( sizeof(vector< string >)) ;
*u = vector< string >(10,"test");
system("pause");
}
My understanding is that malloc allocates memory to the size of a vector (which is 12 bytes) and then it is then deferenced and the constructor is called to fill that memory. I may be wrong.
Its probally something simple. Or not. I'm using the dev C++ compiler