Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Structure Initialization

Structure Initialization

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++tutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aman2006
    wrote on last edited by
    #1

    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

    T R 2 Replies Last reply
    0
    • A aman2006

      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

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      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 a 0). you have two possibilities :

      first one :
      CATEGORY_CODE stCatCode = {
      "",
      0,
      "",
      0,
      0
      }; // Values are given by default for a nil initialisation

      with 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

      1 Reply Last reply
      0
      • A aman2006

        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

        R Offline
        R Offline
        Rick York
        wrote on last edited by
        #3

        Give it a constructor that initializes the variables. __________________________________________ a two cent stamp short of going postal.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups