1

Just trying to make my first instance of a class in Visual Studio in C++ but it always leads to error code C2065. Here is my Code:

What am I forgetting? I think this should work:

int main() {
  std::cout << "Hello World" << endl;
  Testerus a;
}

class Testerus {
  int a =3;
}
EricSchaefer
  • 25,272
  • 21
  • 67
  • 103
tridentifer
  • 29
  • 1
  • 4
  • 1
    Try to define your class `Testerus` before the main() function. – vahancho Apr 20 '21 at 08:51
  • Does this answer your question? [What is an 'undeclared identifier' error and how do I fix it?](https://stackoverflow.com/questions/22197030/what-is-an-undeclared-identifier-error-and-how-do-i-fix-it) – Kfir Ventura Apr 20 '21 at 08:53
  • 2
    For future questions about build errors, please copy-paste the full and complete build output into the question. Not everyone know the MSVC error codes by heart. – Some programmer dude Apr 20 '21 at 08:53
  • As for the problem with the code you show, what resources are you using to learn C++? If it doesn't tell you that symbols must be declared (or maybe even defined) before you use the symbols, then perhaps you should consider another resource to learn. – Some programmer dude Apr 20 '21 at 09:05

1 Answers1

0

In your main function you have used extra '{' curly brace in your code plus you have not used semicolon for class definition

class Testerus
{
   int a =3;
};

int main()
{
  std::cout << "Hello World" << endl;
  Testerus a;
}
  • @tridentifer Have you got any updates? If your case has been solved, please help to mark answers. If not, just feel free to contact us. Your understanding and cooperation will be grateful. – Jeaninez - MSFT Apr 28 '21 at 02:56