Structure Initialization
-
Hi I want to initialize this struct struct CATEGORY_CODES { CString strCategoryCode; int nCategoryID; CString strCategoryName; int nHasSubCategory; int nActive; }; if i do CATEGORY_CODE stCatCode = {0}; I get the Fatal error on CString members if i try to insert the values init. Can anybody help me how to intialize the structures in MFC thanks shailesh
-
Hi I want to initialize this struct struct CATEGORY_CODES { CString strCategoryCode; int nCategoryID; CString strCategoryName; int nHasSubCategory; int nActive; }; if i do CATEGORY_CODE stCatCode = {0}; I get the Fatal error on CString members if i try to insert the values init. Can anybody help me how to intialize the structures in MFC thanks shailesh
it is not an MFC problem, it is a simple C rule ! if you write
{0}
, the compiler wont accept for such strusture because it doesn't contain only one member (an such member cannot be stored with a0
). you have two possibilities :first one :
CATEGORY_CODE stCatCode = {
"",
0,
"",
0,
0
}; // Values are given by default for a nil initialisationwith a GNU compiler, you could also write :
CATEGORY_CODE stCatCode = {
strCategoryCode: "",
nCategoryID: 0,
strCategoryName: "",
nHasSubCategory: 0,
nActive: 0
};second one :
CATEGORY_CODE stCatCode;
stCatCode.strCategoryCode = "";
stCatCode.nCategoryID = 0;
stCatCode.strCategoryName = "";
stCatCode.nHasSubCategory = 0;
stCatCode.nActive = 0;is that ok for you ?
TOXCCT >>> GEII power
-
Hi I want to initialize this struct struct CATEGORY_CODES { CString strCategoryCode; int nCategoryID; CString strCategoryName; int nHasSubCategory; int nActive; }; if i do CATEGORY_CODE stCatCode = {0}; I get the Fatal error on CString members if i try to insert the values init. Can anybody help me how to intialize the structures in MFC thanks shailesh