Click here to Skip to main content
15,887,135 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
GeneralRe: Is CString really based on TCHAR? Pin
Rajesh R Subramanian30-Jul-11 22:44
professionalRajesh R Subramanian30-Jul-11 22:44 
Questionbasic C struct newbee question Pin
Member 811717127-Jul-11 9:01
Member 811717127-Jul-11 9:01 
GeneralRe: basic C struct newbee question Pin
David Crow27-Jul-11 10:14
David Crow27-Jul-11 10:14 
GeneralRe: basic C struct newbee question Pin
Member 811717127-Jul-11 10:38
Member 811717127-Jul-11 10:38 
GeneralRe: basic C struct newbee question Pin
David Crow27-Jul-11 10:52
David Crow27-Jul-11 10:52 
GeneralRe: basic C struct newbee question Pin
Albert Holguin27-Jul-11 12:09
professionalAlbert Holguin27-Jul-11 12:09 
GeneralRe: basic C struct newbee question Pin
Maximilien27-Jul-11 13:13
Maximilien27-Jul-11 13:13 
AnswerRe: basic C struct newbee question Pin
Maximilien27-Jul-11 10:21
Maximilien27-Jul-11 10:21 
AnswerRe: basic C struct newbee question Pin
Albert Holguin27-Jul-11 10:26
professionalAlbert Holguin27-Jul-11 10:26 
GeneralRe: basic C struct newbee question Pin
Member 811717127-Jul-11 10:34
Member 811717127-Jul-11 10:34 
GeneralRe: basic C struct newbee question Pin
Albert Holguin27-Jul-11 12:12
professionalAlbert Holguin27-Jul-11 12:12 
AnswerRe: basic C struct newbee question Pin
«_Superman_»27-Jul-11 10:59
professional«_Superman_»27-Jul-11 10:59 
QuestionHow to Validate User's Password Pin
rick222227-Jul-11 7:53
rick222227-Jul-11 7:53 
AnswerRe: How to Validate User's Password Pin
Rajesh R Subramanian27-Jul-11 8:09
professionalRajesh R Subramanian27-Jul-11 8:09 

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.