I have a class named Fstring
, it has a wchar_t*
in it.
I wrote the following to copy the string literal into Fstring
:
#include <iostream>
using namespace std;
class Fstring{
wchar_t *arr;
public:
Fstring& operator = (const wchar_t temp[])
{
delete [] arr;
arr=new wchar_t[wcslen(temp)];
for(int i=0;i<=wcslen(temp);i++)
arr[i]=temp[i];
return *this;
}
};
int main()
{
Fstring test=L"Hello World";
return 0;
}
But it did not work. The compiler gave me the following error:
error C2440: 'initializing' : cannot convert from 'const wchar_t [12]' to 'Fstring'
I'm really confused, I googled "Overloading operators" but all of results have the same way I used to overload the operator. So why does this not work?