1 Answer
New AnswerIn C++ you should use the 'new' keyword to allocate memory in the heap instead of malloc(). Instead of doing string* ptr = (string*)malloc(sizeof(string)); you can just do: string* ptr = new string; and to free memory you don't use the free() function, you use the 'delete' keyword. Instead of free(ptr); you type: delete ptr; The malloc function might be in C++ (i'm not sure) but from what I've read, you should rarely use it, and should just use 'new' instead.