CString("hai").Format("hello");
-
AfxMessageBox(CString("hai")); //works fine AfxMessageBox(CString("hai").Format("hello")); //gives error, any way to make this work without having a CString variable?.
-
AfxMessageBox(CString("hai")); //works fine AfxMessageBox(CString("hai").Format("hello")); //gives error, any way to make this work without having a CString variable?.
-
AfxMessageBox(CString("hai")); //works fine AfxMessageBox(CString("hai").Format("hello")); //gives error, any way to make this work without having a CString variable?.
-
I'm not quite clear on what you want to achieve. In any case, you cannot use the CString constructor like that in the second case.
I Dream of Absolute Zero
RChin wrote: In any case, you cannot use the CString constructor like that in the second case. I feel its a valid call. But gives an error coz CString::Format() returns void.
suhredayan
There is no spoon. -
RChin wrote: In any case, you cannot use the CString constructor like that in the second case. I feel its a valid call. But gives an error coz CString::Format() returns void.
suhredayan
There is no spoon.suhredayan® wrote: I feel its a valid call. But gives an error coz CString::Format() returns void. You're absolutely correct. My bad :doh:. The following does indeed compile, though how it could be used in a useful way is still a puzzle. (since it cannot be assigned to anything) :|
void MyFunction() { CString("Hey").Format("There!"); }
I Dream of Absolute Zero
-
suhredayan® wrote: I feel its a valid call. But gives an error coz CString::Format() returns void. You're absolutely correct. My bad :doh:. The following does indeed compile, though how it could be used in a useful way is still a puzzle. (since it cannot be assigned to anything) :|
void MyFunction() { CString("Hey").Format("There!"); }
I Dream of Absolute Zero
That compiles *and* runs successfully. The problem is that
CString::Format
's return type isvoid
. So that's the return type of this statement, and there doesn't seem to be any way to convert that to the LPCTSTR that AfxMessageBox expects. It's going to take some serious obfuscation to make this work. My question is...what's wrong with a local CString variable? Like it or not, the statement itself is creating a local CString that goes out of scope after the statement executes. Bob Ciora -
suhredayan® wrote: I feel its a valid call. But gives an error coz CString::Format() returns void. You're absolutely correct. My bad :doh:. The following does indeed compile, though how it could be used in a useful way is still a puzzle. (since it cannot be assigned to anything) :|
void MyFunction() { CString("Hey").Format("There!"); }
I Dream of Absolute Zero
Although this is a valid call, isn't it a bit like asking for "unpredictable results" to come your way ?
CString strText( _T("Hey") );
strText += _T(" there !");Much easier, much simpler, and compiles correctly :D -Antti Keskinen ---------------------------------------------- "If we wrote a report stating we saw a jet fighter with a howitzer, who's going to believe us ?" -- R.A.F. pilot quote on seeing a Me 262 armed with a 50mm Mauser cannon.
-
That compiles *and* runs successfully. The problem is that
CString::Format
's return type isvoid
. So that's the return type of this statement, and there doesn't seem to be any way to convert that to the LPCTSTR that AfxMessageBox expects. It's going to take some serious obfuscation to make this work. My question is...what's wrong with a local CString variable? Like it or not, the statement itself is creating a local CString that goes out of scope after the statement executes. Bob CioraBob Ciora wrote: It's going to take some serious obfuscation to make this work. My question is...what's wrong with a local CString variable? Like it or not, the statement itself is creating a local CString that goes out of scope after the statement executes. Its all about trying to show the geekness, wot you feel cing the following. int fun(tchar* buff,tchar* szFnd,int n) { .... .... return CString(buff).Right(n).Find(szFnd); } ;)
suhredayan
There is no spoon.