0

When I declare an object I have to do this. Class object; However this actually calls the constructor of the object, and results in an error if the constructor needs to take parameters. What is the correct way of declaring an object without defining it in a .h?

w4etwetewtwet
  • 1,330
  • 2
  • 10
  • 20

1 Answers1

1

If you just want to declare an object, not define an object, you should use the keyword "extern":

extern YourClass yourObject;

the statement above can be placed either in .h or .cpp without any problem.

nicky_zs
  • 3,633
  • 1
  • 18
  • 26