According to the one definition rule, class and struct definitions must not repeat in a single translation unit.
But then why is the case that they are allowed to be repeated in multiple translation units, if they are in reality definitions. Why doesnt the linker throw a multiple definition error in that case ?
E.g. - Following should throw a multiple definition error by the same logic
test.h
#ifndef TEST
#define TEST
class s {
int a;
int b;
};
#endif
test1.cpp
#include "test.h"
int main() {}
test2.cpp
#include "test.h"