CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2011
    Posts
    29

    How do access a variable updated in a cpp file to another cpp file?

    Hi,
    I have two cpp files.I m updating a value of an integer in one cpp file and i want to perform a specific function in the second file as per to the value updated in the first file.
    ie
    I m initialing the variable in the constructor.
    I have two buttons in the first cpp file. On clicking the first button I m updating the variable as 1 and on pressing button two , I m updating the variable as 2.
    I m retrieving this variable in the second cpp file with respect to the object created for the class in the first cpp file.

    The problem is that i m not able tot retrieve the updated value in the second file. only the initialized value is being retrieved. neither 1 nor 2 is updated.

    Thankx a ton in advance.. !!

    Regards ,
    Sandhya.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: How do access a variable updated in a cpp file to another cpp file?

    Quote Originally Posted by sandy2511 View Post
    Hi,
    I have two cpp files.I m updating a value of an integer in one cpp file and i want to perform a specific function in the second file as per to the value updated in the first file.
    ie
    I m initialing the variable in the constructor.
    I have two buttons in the first cpp file. On clicking the first button I m updating the variable as 1 and on pressing button two , I m updating the variable as 2.
    I m retrieving this variable in the second cpp file with respect to the object created for the class in the first cpp file.

    The problem is that i m not able tot retrieve the updated value in the second file. only the initialized value is being retrieved. neither 1 nor 2 is updated.

    Thankx a ton in advance.. !!

    Regards ,
    Sandhya.
    Your question has nothing to do with the Windows API, and honestly has nothing to do with button presses. Also, there are no "cpp files" when you run a program -- you have an executable file that has no idea about what C++ source files were used to create it.

    Your question is a C++ language question, more probably dealing with the extern keyword and/or internal/external linkage issues, therefore it should be posted in the Non-Visual C++ forum.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: How do access a variable updated in a cpp file to another cpp file?

    [ Redirected thread ]
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: How do access a variable updated in a cpp file to another cpp file?

    Typically you'd just pass the value as an argument to your function.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured