c++ - Why classes in different files do not find each other without a header? -


please have @ following code

main.cpp

#include <iostream>  using namespace std;  int main() {     class1 c; } 

class1.cpp

#include <iostream>  using namespace std;  class class1 { public:     void click1()     {         cout << "click 1" << endl;     } }; 

class2.cpp

#include <iostream>  using namespace std;  class class2 { public:     void click2()     {         cout << "click 2" << endl;     } }; 

if add header files above classes, work. why c++ not understand classes in different files without header file?

in c++ source file called translation unit. each translation unit separate each other, , don't know each others existence. have explicitly tell compiler things translation unit should know about.

this done declaring things. , instead of having same declaration in many files , places, put them in single header file source files includes.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -