Gloval variable in C++ Winform

José Carlos 886 Reputation points
2022-12-12T15:53:31.257+00:00

Good morning friends.

I have a small application for my own use developed in C++ Winforms. The application has only two forms. One main with menu and another with operations. I need to create a global variable on the main form, but that I can change its value on the other form and return that value to the main form.

In the main form I put static int flag; When I use the variable in the other form it gives an error message saying: flag::undeclared identifier.

How to solve it?

Thanks

Developer technologies C++
{count} votes

2 answers

Sort by: Most helpful
  1. YujianYao-MSFT 4,296 Reputation points Microsoft External Staff
    2022-12-13T05:25:17.483+00:00

    Hi @Anonymous ,

    Did you make the two header files include each other?

    Doing so will lead to the problem you mentioned, I suggest you refer to the solution in this issue.

    Best regards,

    Elya


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. José Carlos 886 Reputation points
    2022-12-15T09:51:19.74+00:00

    Hello
    I put it in the topic already answered by you in the article "Update textbox on another form - C++ Winforms" with a screen example, because this solution does not suit me. Did not work. I believe it's the type of application. Take a look at my question, because I think you will understand and for sure you will get the ultimate solution for me.
    Thanks a lot again.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.