locked
how do I access struct variable from another file? RRS feed

  • Question

  • another newbie question.

    I am moving functions which use this struct into another file.   how do I access sData in another file? 

    typedef struct sVData
    {
        int i;
    }
    sVData;

    static sVData sData;

     

    Thanks again.  -Greg

    Thursday, August 3, 2006 8:33 PM

Answers

  • Are you really sure you want a static instance of the struct at global scope? You may run in to issues regarding the initialization order of such and other of your objects, and should therefore thread forth with extreme caution.

    Typically, you would define a class in one file (a .h), implement it in another (a .cpp), then include the definition in another .h or .cpp. To access data within it, you create instances of the struct, in this case e.g. as sVData sData, then refer to the members with sData.i.

    Thursday, August 3, 2006 9:18 PM

All replies

  • Are you really sure you want a static instance of the struct at global scope? You may run in to issues regarding the initialization order of such and other of your objects, and should therefore thread forth with extreme caution.

    Typically, you would define a class in one file (a .h), implement it in another (a .cpp), then include the definition in another .h or .cpp. To access data within it, you create instances of the struct, in this case e.g. as sVData sData, then refer to the members with sData.i.

    Thursday, August 3, 2006 9:18 PM
  • Thank you Einaros. Your explanation makes very good sense. I'm looking at the codebase now to see how I can achieve that. I'll ask the current team lead about the issues you raised. The struct currently is static. In and of itself that may be o.k. but I understand your caution about the initialization order. -greg
    Thursday, August 3, 2006 9:41 PM
  •  

        I am a newbie here...

        studying from everyone here...

        Thanks in Advance...

    Tuesday, August 8, 2006 9:30 AM