| | | | Browse by category |
Article ID: 433
Last updated: 27 Apr, 2018
Problem
Problems with the expression GetUserAttribute(IDS_MYATTRIBUTE) == 1
Cause
Action
The problem is that GetUserAttribute() returns const CString& and therefore the expression
style.GetUserAttribute(IDS_MYATTRIBUTE) == 1 |
evaluates to FALSE because the string is converted to a LPCTSTR and C++ only compares the pointers but not the contents of the string.
You can see the same behavior if you take a look at the following statement:
const CString& xgets(CString s) { return s; } CString s = 1; ASSERT(xgets(s) == 1); |
The statement will assert.
If you return a CString instead,
CString xgets(CString s) { return s; } CString s = 1; ASSERT(xgets(s) == 1); |
C++ converts 1 to a CString instead and the statement will not assert.
To work around the problem use the following lines instead:
- call:
-
if (atoi(colstyle.GetUserAttribute(IDS_MYATTRIBUTE).GetValue())==1) - call:
-
if (colstyle.GetUserAttribute(IDS_MYATTRIBUTE).GetValue()==(CString) 1) - or simply call:
-
if (colstyle.GetUserAttribute(IDS_MYATTRIBUTE)==(CString) 1)
This article was:
Helpful |
Not helpful
Report an issue
Article ID: 433
Last updated: 27 Apr, 2018
Revision: 3
Views: 1714
Posted: 11 Jan, 2001 by
Meltreger B.
Updated: 27 Apr, 2018 by
Meltreger B.
Others in this category
Powered by KBPublisher (Knowledge base software)