|
Windows 7, visual Studio 2008, C++
WCHAR *op_type = NULL;
if( x )
op_type = &L"First";
else
op_type = &L"Second";
This solicits the error
Quote: error C2440: '=' : cannot convert from 'const wchar_t (*)[6]' to 'WCHAR *'
What is my syntax error?
I tried the declaration:
const wchar_t *op_type2 = NULL;
and received the error:
Quote: error C2440: '=' : cannot convert from 'const wchar_t (*)[6]' to 'const wchar_t *'
Which seems wrong to me. Why does the pointer care how long the string is? It is but the address of the first character.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
modified 7-Jun-14 20:28pm.
|
|
|
|
|
For the first part of your question, you do not need the & sign.
WCHAR *op_type = NULL;
if( x )
op_type = L"First";
else
op_type = L"Second";
For the second part of your question, you should not be getting any errors.
It is a valid statement.
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
Lets see if I really understand what you told me.
The declaration:
const WCHAR *op_type = NULL;
was good. The use:
op_type = &L"Shutdown";
was incorrect. The declaration of the constant string:
&L"Shutdown";
is effectively a WCHAR array. Arrays are always passed by address so adding the & symbol was creating an pointer to a pointer. The error message:
Quote: error C2440: '=' : cannot convert from 'const wchar_t (*)[9]' to 'const WCHAR *'
was telling me that but I was too wrapped up in reading the [9] as a length rather than an indicator that this is an array and the address is passed rather than the value.
Thank you for helping me with this.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
You logic is flawed but your result is correct.
The "L" prefix is a sort of precompiler literal Microsoft has put in place it's not a macro or such and it is sort of bound like the quotes are in the precompiler
look at how you write a normal string constants
const char* txtcnst = "SOME_CONSTANT_TEXT";
There is no "&" pointer there so why just because you want a unicode string would they change it
The answer is it is the way it is because that is how C language defined the use of constants and think of L as part of the quotes "" simply telling the compiler the text is unicode format.
In vino veritas
|
|
|
|
|
|
Is this line of code valid in C++:
int a{1};
|
|
|
|
|
|
|
My searches revealed only a partial answer to int a{1};
What does this do and why might I use it?
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
|
I should have included "initialize" in my search.
On one hand it really doesn't add anything.
On the other, it can standardize initialization methods. An int can be initialized in the same manner as an array. That is of little significance, but often consistency adds more than is immediately apparent.
Thanks for taking the time to reply.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
Hi,
Yes. This is the new direct list initialization available in C++11.
Best Wishes,
-David Delaune
|
|
|
|
|
Thank you for your reply.
|
|
|
|
|
Friends, how to compress speex ogg packets into a *. Oog file?(can make music player play the files)
please!
|
|
|
|
|
I am getting the errors related to WiX Toolset while compiling one of the applications of C++ in VS2005.
The error message shows that:
"WiX Toolset compiler has encountered a problem and needs to close".
I googled for the related information and tried by installing the 2007 version of Toolset compiler wix38.exe. But still not able to resolve the issue.
Please let me know how to rectify the error..
|
|
|
|
|
Without any more detail no one can guess what is wrong. You would be better posting your query on a forum dedicated to this product, since it has nothing to do with C++ per se.
|
|
|
|
|
Why the generated *. Ogg cannot play?
|
|
|
|
|
|
I am watching a video where B. Stroustrup talks about c++ - link-> (31:23) ()[^]
I have trouble understanding the RAII slide:
http://www.upload.ee/image/4090006/raii.png
1) Why doesn't he catch the exception?
2) I keep reading that when constructor throws, the destructor of an object is never called.
Regards
|
|
|
|
|
1) In a real program he most likely catches it in the code that tries to create the object.
2) If the constructor throws an exception then the object is not created so there is no destructor to call.
3) Why not ask Stroustrup?
|
|
|
|
|
1) Why should he?
2) That's fine: if the constructor cannot open the file then the destructor fclose call doesn't make sense.
Veni, vidi, vici.
|
|
|
|
|
Why doesn't he use the handle?
It's for illustration purposes only.
|
|
|
|
|
Where can I update the edit field to reflect changes of the file name to save?
I have customized my save file dialog and use CFileDlgEventHandler. There i need to set a different filename.
In the file save dialog I select a filename from existing files, e.g. blah.tif. After clicking a custom checkbox I need to set e.g. blah_C1.tif. I can get and set the filename inside the handler:
CComQIPtr<ifiledialog> pDlg = pfdc;
pDlg->GetFileName(...) and pDlg->SetFileName(...) work,
but after clicking 'Save' I get the filename previously selected (blah.tif) and not the changed one.
Anyone out there with a tip to update the edit control behind the scenes?
|
|
|
|
|
Have you tried overriding the CFileDialog class (MFC)? ...that should be easier to accomplish using MFC. In order to change the text, you just need to get the control ID (use Spy++ if you can't find documentation as to the ID) and set the new text using SetWindowText()[^].
|
|
|
|
|
I use the new Vista/W7 style COM dialogs, which use a different interface (not MFC). Hmm, obviously wrong forum (...as always...). I'll pass it to COM forum.
The problem is that there must be another control above the edit control (checkbox), which holds the filename, too. The interface does not offer a function to set the filename of the checkbox. I can set the filename of the edit, but it is not passed through, when hitting OK.
|
|
|
|