I think that I misunderstood something about class definitions in c++...
Why it is legal to define class in multiple files, like this:
file Test.cpp:
#include <iostream>
using namespace std;
void testFunc();
class A
{
public:
void printText();
} clA;
void A::printText()
{
cout << "file: Test.cpp, class: A, method: void printText" << endl;
}
int main()
{
clA.printText();
testFunc();
getchar();
return 0;
}
file NewFile.cpp:
#include <iostream>
using namespace std;
void testFunc();
class A
{
public:
int printText();
} clB;
int A::printText()
{
cout << "file: NewFile.cpp, class: A, method: int printText" << endl;
return 0;
}
void testFunc()
{
clB.printText();
}
Do You see that there are definitions for class A, but the methods are little bit dirrefent: void printText and int printText. This project will compile just fine, but if we try to put these methods in one definition file, there will be an error:
class A
{
public:
void printText();
int printText();
}
So why we can overcome this and create class definition in more than one file?
I thought that maybe class A from Test.cpp and class A from NewFile.cpp are not the same classes, and then clA and clB are objects of different types, but if we check these objects via typeid, then we see that they are of the same type...
Also, the clA and clB objects are of the same type (if we check it via typeid).