Click here to Skip to main content
15,897,187 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: overloading operator<<() vs. namespaces Pin
Rick York31-Jul-11 7:02
mveRick York31-Jul-11 7:02 
GeneralRe: overloading operator<<() vs. namespaces Pin
Michal Kaut31-Jul-11 22:32
Michal Kaut31-Jul-11 22:32 
GeneralRe: overloading operator<<() vs. namespaces Pin
Rick York3-Aug-11 12:36
mveRick York3-Aug-11 12:36 
QuestionMapping of file Pin
sarfaraznawaz28-Jul-11 21:42
sarfaraznawaz28-Jul-11 21:42 
AnswerRe: Mapping of file Pin
«_Superman_»29-Jul-11 3:37
professional«_Superman_»29-Jul-11 3:37 
GeneralRe: Mapping of file Pin
sarfaraznawaz29-Jul-11 20:30
sarfaraznawaz29-Jul-11 20:30 
GeneralRe: Mapping of file Pin
Richard Andrew x6431-Jul-11 6:30
professionalRichard Andrew x6431-Jul-11 6:30 
QuestionIssue with ShellExecute on Windows 7 in windows service application Pin
Ganesh_T28-Jul-11 21:14
Ganesh_T28-Jul-11 21:14 
AnswerRe: Issue with ShellExecute on Windows 7 in windows service application Pin
«_Superman_»29-Jul-11 3:25
professional«_Superman_»29-Jul-11 3:25 
QuestionGet Active WIndow Name Pin
Anu_Bala28-Jul-11 20:35
Anu_Bala28-Jul-11 20:35 
AnswerRe: Get Active WIndow Name Pin
«_Superman_»29-Jul-11 3:41
professional«_Superman_»29-Jul-11 3:41 
QuestionTypedef struct help Pin
WebDev.ChrisG28-Jul-11 9:13
WebDev.ChrisG28-Jul-11 9:13 
AnswerRe: Typedef struct help Pin
Richard Andrew x6428-Jul-11 9:20
professionalRichard Andrew x6428-Jul-11 9:20 
GeneralRe: Typedef struct help Pin
WebDev.ChrisG28-Jul-11 9:23
WebDev.ChrisG28-Jul-11 9:23 
GeneralRe: Typedef struct help Pin
Richard Andrew x6428-Jul-11 9:25
professionalRichard Andrew x6428-Jul-11 9:25 
GeneralRe: Typedef struct help Pin
Albert Holguin28-Jul-11 9:43
professionalAlbert Holguin28-Jul-11 9:43 
GeneralRe: Typedef struct help Pin
Albert Holguin28-Jul-11 10:11
professionalAlbert Holguin28-Jul-11 10:11 
QuestionIs CString really based on TCHAR? Pin
Dean Seo27-Jul-11 20:50
Dean Seo27-Jul-11 20:50 
AnswerRe: Is CString really based on TCHAR? Pin
Rajesh R Subramanian27-Jul-11 21:05
professionalRajesh R Subramanian27-Jul-11 21:05 
GeneralRe: Is CString really based on TCHAR? Pin
Dean Seo27-Jul-11 21:31
Dean Seo27-Jul-11 21:31 
AnswerRe: Is CString really based on TCHAR? Pin
Rajesh R Subramanian27-Jul-11 21:51
professionalRajesh R Subramanian27-Jul-11 21:51 
GeneralRe: Is CString really based on TCHAR? [modified] Pin
Dean Seo28-Jul-11 19:35
Dean Seo28-Jul-11 19:35 
Rajesh R Subramanian wrote:
I recommend that you read the 3 articles I linked you to, and that will clear up a lot of your doubts.

I read those 3 articles all the way through and it did help. Thank you.
I will print out those articles and read again anytime I need.

Rajesh R Subramanian wrote:
That code may compile, but it may or may not work depending on what you intend to do with the _tstr variable.

By the way, in that case, the thing is that that code doesn't even comfile and it occurs an 'casting failed' error.
So I just made a simple example that claify why this happens.

class A{
public:
        // I didn't allocate any block of memory on m_WideCharacter to make it simpler.
	const wchar_t* m_WideCharacter;  

	operator const wchar_t*() const{
		return m_WideCharacter;
	}
};
int _tmain(int argc, _TCHAR* argv[])
{
	A aaa;
	wchar_t* _WideCharacter = aaa;  // error-the operator method can't be called.
        wchar_t* _WideCharacter = (wchar_t*)aaa // error-the operator method can't be called.
        wchar_t* _WideCharacter = (wchar_t*)(const wchar_t*)aaa // works!
	return 0;
}

I think I just misunderstood how const and operator() that returns const value in C++ works.

To make operator const wchar_t*() const return the value, we definitely need the type casting (const wchar_t*) first, otherwise the compiler wouldn't understand if the operator method in class A can be possibly called.
And that is what (const wchar_t*) is for. That's it.

That is why in that MFC based code I need to write (LPCTSTR*) because CString only has operator PCXSTR(), which is the same as operaotr const wchar_t*(), and the only way that the operator PCXSTR() is called is to write (LPCTSTR*) for type casting.

Am I correct? Or am I not clear enough???

modified on Friday, July 29, 2011 1:52 AM

AnswerRe: Is CString really based on TCHAR? Pin
Rajesh R Subramanian28-Jul-11 20:57
professionalRajesh R Subramanian28-Jul-11 20:57 
GeneralRe: Is CString really based on TCHAR? Pin
Rajesh R Subramanian29-Jul-11 8:16
professionalRajesh R Subramanian29-Jul-11 8:16 
GeneralRe: Is CString really based on TCHAR? Pin
Dean Seo30-Jul-11 20:43
Dean Seo30-Jul-11 20:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.