#ifndef UNICODE
#define UNICODE
#endif
#include <iostream>
#include <queue>
#include <stdio.h>
#include <Windows.h>
#include <string>
using namespace std;
int __cdecl main()
{
std::queue<std::basic_string<TCHAR>> results;
results.push(TEXT("Hello world! ♥☻☺"));
wcout<<results.front();
delete [] results.front();
system("pause");
return 0;
}
Error 1 error C2440: ‘delete’ : cannot convert from
‘std::basic_string<_Elem,_Traits,_Ax>’ to ‘void
*’ C:\Users\Tomek\Documents\Visual Studio 2010\Solutions\clean_rough_draft\clean_rough_draft\main.cpp 20 1 clean_rough_draft
Why such error is being thrown and how to fix it?
Your first problem was you forgot to include
<string>.Your current problem is your delete makes no sense. Your string isn’t dynamically allocated, and front() returns a reference to it anyway. So, you’re trying to call array delete on something that isn’t an array (a string is an object that encapsulates an array) and that wasn’t dynamically allocated in the first place (and on a reference instead of a pointer).