Share via

Working with Classes

srfpala 111 Reputation points
2020-12-09T00:07:06.88+00:00

I'm just learning Classes and Objects.
I have a Windows CppCLR_Winforms App built with VS2019.
I have MyClass.h and MyClass.cpp files in the project.
In Form1.h I have a button. On the button click I'd like to instantiate an object
MyClass myObj;
Add member data and display that data.
But in btnShowData_Click() I try
MyClass myObj; // Instantiate a MyClass object
but the compiler indicates MyClass is an undeclared identifier.
So where should the MyClass be identified ?
And where should myObj be instantaintiated?
TIA
Bob

Developer technologies | C++
Developer technologies | 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.

0 comments No comments

1 answer

Sort by: Most helpful
  1. David Lowndes 4,731 Reputation points
    2020-12-09T00:16:55.483+00:00

    From what you've said, I'd assume you just need to #include "MyClass.h" from Form1.h.

    Was this answer helpful?

    0 comments No comments

Your answer

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