question

srfpala avatar image
0 Votes"
srfpala asked DanielZhang-MSFT edited

Why an Undefined Identifier ?

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

c++windows-forms
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You mention frmAddAccount.h sometimes, and frmNewAccount.h other times. Which one are you actually including, and which one defines frmAddAccount class?

0 Votes 0 ·
OmkritPandey-5444 avatar image
0 Votes"
OmkritPandey-5444 answered

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;

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DanielZhang-MSFT avatar image
0 Votes"
DanielZhang-MSFT answered

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.



161.png (11.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

srfpala avatar image
0 Votes"
srfpala answered DanielZhang-MSFT edited

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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @srfpala,
I added new Windows Form via your description, and I had the same problem as you.
The problem is mainly related to this extension, so I suggest you ask for his publisher in here.
54188-171.png
Best Regards,
Daniel Zhang


0 Votes 0 ·
171.png (26.3 KiB)