I am learning about C++ classes and I realized that if I tried to move my class declaration and definition of class Date from main.cpp to another c++ file, say test.cpp and compiled the two files I got an error saying Date was not declared. Why is that?
I am learning about C++ classes and I realized that if I tried to
Share
This is why you have header files. You need a header file
test.hthat contains only the class definition (that is mostly function declarations) andtest.cppthat contains the actual function definitions (the code).In
main.cppyou’ll have to#include "test.h".