What is the difference between these two and why does one compile fine compared to the other :S
//MyFile.h
#include<iostream>
using namespace std;
inline std::ostream& operator << (std::ostream& Str, const RGB &Rgb)
{
Str<<"R: "<<(int)Rgb.R<<" G: "<<(int)Rgb.G<<" B: "<<(int)Rgb.B;
return Str;
}
//Main.cpp
#include <iostream>
#include "MyFile.h"
using namespace std;
int main()
{
cout<<Rgb(16777215); //Results in an error!
}
The above gives an error but the below thing does not:
//Main.cpp
#include <iostream>
using namespace std;
inline std::ostream& operator << (std::ostream& Str, const RGB &Rgb)
{
Str<<"R: "<<(int)Rgb.R<<" G: "<<(int)Rgb.G<<" B: "<<(int)Rgb.B;
return Str;
}
int main()
{
cout<<Rgb(16777215); //Results are printed correctly.
}