Accessing variables...

Discussion in 'C++' started by Jurek Dabrowski, Jan 27, 2007.

  1. hi all,

    I have a question in reference to accessing variables in another class maybe
    someone has dealt with before.
    I have some public variables declared in my main plug-in class
    CCommandMeshToSrf,
    eg: BOOL m_bHaveAnswer;
    I want to set this variable from within a dialog class which is defined in
    separate .h and .cpp files of course. How would one access this varibale
    from a method defined in my CTestModelessDialog class ?

    I had this working in a previous version by declaring a pointer to the main
    plug-in
    class:
    CCommandMeshToSrf *m_cmd; and then accessing the public vairable in the
    CTestModelessDialog class by using:

    m_cmd->m_bHaveAnswer

    Recently, it shows up as an undefined variable and crashes....any ideas
    ?



    thanks,

    jurek
     
    Jurek Dabrowski, Jan 27, 2007
    #1
    1. Advertising

  2. Jurek Dabrowski

    Daniel T. Guest

    In article <32Nuh.13932$>,
    "Jurek Dabrowski" <> wrote:

    > hi all,
    >
    > I have a question in reference to accessing variables in another class maybe
    > someone has dealt with before.
    > I have some public variables declared in my main plug-in class
    > CCommandMeshToSrf,
    > eg: BOOL m_bHaveAnswer;
    > I want to set this variable from within a dialog class which is defined in
    > separate .h and .cpp files of course. How would one access this varibale
    > from a method defined in my CTestModelessDialog class ?
    >
    > I had this working in a previous version by declaring a pointer to the main
    > plug-in
    > class:
    > CCommandMeshToSrf *m_cmd; and then accessing the public vairable in the
    > CTestModelessDialog class by using:
    >
    > m_cmd->m_bHaveAnswer
    >
    > Recently, it shows up as an undefined variable and crashes....any ideas
    > ?


    Did you initialize it?
     
    Daniel T., Jan 27, 2007
    #2
    1. Advertising

  3. Jurek Dabrowski

    Jim Langston Guest

    "Jurek Dabrowski" <> wrote in message
    news:32Nuh.13932$...
    > hi all,
    >
    > I have a question in reference to accessing variables in another class
    > maybe
    > someone has dealt with before.
    > I have some public variables declared in my main plug-in class
    > CCommandMeshToSrf,
    > eg: BOOL m_bHaveAnswer;
    > I want to set this variable from within a dialog class which is defined in
    > separate .h and .cpp files of course. How would one access this varibale
    > from a method defined in my CTestModelessDialog class ?
    >
    > I had this working in a previous version by declaring a pointer to the
    > main
    > plug-in
    > class:
    > CCommandMeshToSrf *m_cmd; and then accessing the public vairable in the
    > CTestModelessDialog class by using:
    >
    > m_cmd->m_bHaveAnswer
    >
    > Recently, it shows up as an undefined variable and crashes....any ideas
    > ?
    >
    >
    >
    > thanks,
    >
    > jurek


    "Recently, it shows up as an undefined varaible and crashes..." That is an
    oxymoron. If it is an undefined variable, it won't compile. I has to
    compile to crash, and if it compiles it's not an undefined variable.

    If it fails to compile (link error) then most likely you forgot to include
    the header file (.h) in the other .cpp file.

    If it crashes, then maybe it's not initialized.

    The normal way is to pass a pointer, or better yet, a reference.

    Please show code and the actual error/crash if this doesn't help.
     
    Jim Langston, Jan 27, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    643
    Teemu Keiski
    Jul 9, 2003
  2. Salek Talangi

    Accessing variables of another class

    Salek Talangi, Jul 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    435
    Kevin Spencer
    Jul 28, 2003
  3. Ekul
    Replies:
    2
    Views:
    681
  4. dwok
    Replies:
    7
    Views:
    731
    Hal Rosser
    Mar 4, 2005
  5. Replies:
    9
    Views:
    1,013
Loading...

Share This Page