Why my MSVS2008 compiler is not able to find implicit type conversion SrcT -> LPCSTR -> DstT when calling a function? This works fine in other cases. I do not like writing manual conversion all the time like following: MyFunc((LPCSTR)src). What I'm missing?
MyFunc(src);
1>d:\test\test.cpp(39) : error C2664: 'MyFunc' : cannot convert parameter 1 from 'SrcT' to 'DstT'
#include <windows.h>
#include <tchar.h>
class SrcT
{
public:
operator LPCSTR() const
{
return "dummy";
}
};
class DstT
{
public:
DstT() : m_value(NULL) {};
DstT(LPCSTR value) {m_value = value; }
DstT& operator=(LPCSTR value) { m_value = value; return *this; }
LPCSTR m_value;
};
void MyFunc(DstT dst)
{
}
int _tmain(int argc, _TCHAR* argv[])
{
SrcT src;
DstT dst(src);
DstT dst2;
dst2 = src;
MyFunc((LPCSTR)src);
MyFunc(src);
return 0;
}