Hello i have a code like this in c++:
#include <iostream>
using namespace std;
namespace exercises
{
class String;
ostream& operator<<(ostream&, const String&);
istream& operator>>(istream&, String&);
class String
{
public:
explicit String(const char* str_="");
~String();
String(String const &oStr_);
String& operator=(const String& oStr_);
String& operator=(const char* oStr_);
bool operator==(const String& oStr_)const;
bool operator<(const String& oStr_)const;
bool operator>(const String& oStr_)const;
char operator[](std::size_t)const;
char& operator[](std::size_t);
const std::size_t Len()const;
const char* CStr()const;
private:
char* m_str;
};
}
but i don't know one thing. i can set all functions (with source) inside this code header file and it's work completely so why people use .lib file when they can set all the sources inside the header file and just include the header file and enjoy it ? i know one thing : header file is for declaration and .cpp is for sources because if you set source inside the header file you maybe get some undefined error (but i didn't) so is it important for me to set my soruces in cpp file or just i can use header file for sources?