I know that you should only declare a function in header and avoid define it because if more than one source file include this header ,the linker will tell you there are duplicate symbol.
I also know that it is recommended that declare a class in header and implement the member function in source file
But here is my question : I try to define the whole class in header (including all the implementation of member function) ,then I found that there was no error from linker when I include this header in two source files.
Here is my header.h file
class ctr { public: ctr(); ctr(char *s); int showname(){return 0;} private: char *name; }; In other two file, I include header.h
//file1.cpp #include header.h //file2.cpp #include header.h Then compile them g++ file1.cpp file2.cpp
So can anyone tell me why normal function definition will give me an error but class definition is ok?
inlined