c++ - overloading << and using namespace std -
i need understanding following:
i overloaded << operator. wrote test program. didnt include "using namespace std" code. program worked out well.
#include <iostream> #include "fraction.h" //using namespace std; int main(void) { //constructing 2 fractions fraction a(4, 2); fraction b(17, 11); //modifying them entering fractions keyboard cin>>a; cin>>b; //computing product , quotient , printing them using cout cout<<a*b<<endl; cout<<a/b<<endl; }
but can see used "endl" standard namespace. can explain me "paradox" m getting here.
p.s didnt include .h , .cpp file because think irrelevant.
when #include
something, straight text replacement file. since #include "fraction.h"
, has line
using namespace std;
the main file uses std
.
also note, not practice using namespace std;
in header files since everywhere else includes header automatically use std
can cause conflicts if programmer unaware.
Comments
Post a Comment