Why an Undefined Identifier ?

srfpala 111 Reputation points
2021-01-06T01:06:45.767+00:00

Using CppCLR_Winforms App (extension by Kaiser ) on Win10

{ // `Trying this code in the frmMain btnAddAccount_Click event:
// I have in this project a frmAddAccount.h file
// And have modified it in the Designer
// This #include "frmNewAccount.h" is present in the frmMain.h file
// frmAddAccount^ f1 = gcnew frmAddAccount(); // Fails but why ?
// 7 Errors are generated. and identifier frmAddAccount is undefined seems
// most relevant
So how and where should frmAddAccount be defined?
I thought the frmAddAccount^ f1 ... statement should do it !

TIA
srfpala

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,901 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,757 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Omkrit Pandey 1 Reputation point
    2021-01-06T06:13:43.863+00:00

    Undefined identifires-
    First we have to know proper definition of identifire. Identifires are the name storage buffer of any program. Sometimes we declare it but did not define it. In that case it picks garbage value and assigned in program .
    That's called undefined identifire.
    e.g. int a;
    cout<<a;

    0 comments No comments

  2. Daniel Zhang-MSFT 9,626 Reputation points
    2021-01-06T06:40:18.513+00:00

    Hi srfpala,
    >> I have in this project a frmAddAccount.h file
    How did you add frmAddAccount.h? And what did "frmAddAccount" mean? a Header File(.h) or else?
    It is better to provide some code segment about your frmAddAccount.h.
    If it is just Header File , I made a test you can refer to.
    First, I add a a frmAddAccount.h file into Headerdateien folder and modify it as follows:
    (Right click Headerdateien folder-> Add->New Item )
    53923-161.png
    frmAddAccount.h

     #pragma once  
        class Test{  
        public:int a;  
                  
        };  
    

    Then add #include "frmAddAccount.h" into frmMain.h file
    Next use it in button click event.

    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {  
    		Test t;  
    		t.a = 5;  
    	}  
    

    If "frmAddAccount" is a Windows Form, I have provided a suggestion in your another thread you can refer to.
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    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.

    0 comments No comments

  3. srfpala 111 Reputation points
    2021-01-07T00:16:43.627+00:00

    Response to Daniel Zhang
    I'll add a MyForm1 to my project and replicate your statements from Project7
    Add | New item | UI | Windows Form | Myform1.h (but can't see it in Design View)
    Note that I didn't use Header file but UI instead. I'll try Header File tomorrow.
    So I save and exit VS2019, Restart VS2019 and reload project and now the design view works as expected and I can see MyForm1 as expected.
    In the btnAddAccount_Clickevent I replicate your statements
    MyForm1^ f1 = gcnew MyForm1();
    f1->ShowDialog();
    and MyForm1, f1 and MyForm1 are each underscored in red
    but btnAddAccount_Clickevent isn't underlined in the actual code

    The first MyForm1 error says identifier MyForm1 is undefined.
    The second MyForm1 error says expected a type specifier.
    The f1 error says identifier f1 is undefined.

    So obviously there is something else going on that I can't see.
    I can see MyForm1.h in the Solution Explorer List,
    and in the Form Design view.

    Again, TIA for your attention and time.


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.