Error with class definition in header file

Brenda 21 Reputation points
2020-09-05T22:45:01.973+00:00

I built the example program from the "Header files (C++)" guide, and when I compile the solution I get a number of errors because the class 'my_class' is not recognized by 'my_class.cpp' nor 'my_program.cpp' (codes C2065, C2653, etc).

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,753 questions
0 comments No comments
{count} votes

Accepted answer
  1. WayneAKing 4,921 Reputation points
    2020-09-06T01:14:16.007+00:00

    I presume you are referring to the example here:

    Header files (C++)
    https://learn.microsoft.com/en-us/cpp/cpp/header-files-cpp?view=vs-2019

    It sounds like you didn't create the header file or add it to the project:

    22794-my-classh.jpg

    • Wayne

1 additional answer

Sort by: Most helpful
  1. Tim Roberts 81 Reputation points
    2020-09-06T01:12:06.92+00:00

    My guess is you didn't copy the code from that page exactly. You have some kind of typo. Double check that your my_class.h has "namespace N" and "class my_class", spelled exactly like that.


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.