Click here to Skip to main content
15,903,385 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to import a namespace Pin
Tim Paaschen3-Jun-07 19:20
Tim Paaschen3-Jun-07 19:20 
QuestionRe: How to import a namespace Pin
john56323-Jun-07 19:35
john56323-Jun-07 19:35 
AnswerRe: How to import a namespace Pin
Tim Paaschen3-Jun-07 23:35
Tim Paaschen3-Jun-07 23:35 
QuestionVideo Display Pin
tyagineha3-Jun-07 18:57
tyagineha3-Jun-07 18:57 
AnswerRe: Video Display Pin
Christian Graus3-Jun-07 19:33
protectorChristian Graus3-Jun-07 19:33 
AnswerRe: Video Display Pin
Amar Sutar3-Jun-07 20:25
Amar Sutar3-Jun-07 20:25 
QuestionRe: Video Display Pin
tyagineha4-Jun-07 0:24
tyagineha4-Jun-07 0:24 
QuestionError in reload operator Pin
Chen-XuNuo3-Jun-07 18:56
Chen-XuNuo3-Jun-07 18:56 
#include<iostream>
#include<string>
#include<cmath>
using namespace std;

class Complex{
public:
Complex();
Complex(double);
Complex(double,double);

void write() const ;
bool operator==(const Complex& ) const ;
bool operator!=(const Complex& ) const ;
Complex operator-();
friend ostream& operator<<(ostream& out,Complex& c);
private:
double real;
double imag;
};

Complex::Complex(){
real=imag=0.0;
}
Complex::Complex(double re){
real=re;
imag=0.0;
}
Complex::Complex(double re,double im){
real=re;
imag=im;
}
void Complex::write() const {
cout<<real<<"+"<<imag<<'i'<<endl;
}
bool Complex::operator==(const Complex& u ) const {
if(real==u.real&&imag==u.imag)
return true;
else return false;
}
bool Complex::operator!=(const Complex& u ) const {
if(real!=u.real||imag!=u.imag)
return true;
else return false;
}

Complex Complex::operator-(){
real=-real;
imag=-imag;
}

ostream& operator<<(ostream& out,const Complex& c)
{
return out<<c.real<<"+"<<c.imag<<'i'<<endl;
}

int main(){
Complex c1(2.3,5.6);
Complex c2(1.4,2.5);
if(c1==c2) {
c1.write();
c2.write();
cout<<c1<<endl;
cout<<c2<<endl;
}
return 0;
}
I have declared :friend ostream& operator<<(ostream& out,Complex& c);
but why the error says:
cannot access private member declared in class 'Complex'?

AnswerRe: Error in reload operator Pin
Rajkumar R3-Jun-07 19:46
Rajkumar R3-Jun-07 19:46 
GeneralRe: Error in reload operator Pin
Chen-XuNuo3-Jun-07 19:52
Chen-XuNuo3-Jun-07 19:52 
GeneralRe: Error in reload operator Pin
Arman S.3-Jun-07 19:58
Arman S.3-Jun-07 19:58 
GeneralRe: Error in reload operator Pin
Rajkumar R3-Jun-07 20:04
Rajkumar R3-Jun-07 20:04 
GeneralRe: Error in reload operator Pin
Chen-XuNuo4-Jun-07 1:02
Chen-XuNuo4-Jun-07 1:02 
GeneralRe: Error in reload operator Pin
Rajkumar R4-Jun-07 1:40
Rajkumar R4-Jun-07 1:40 
GeneralRe: Error in reload operator Pin
Chen-XuNuo4-Jun-07 2:05
Chen-XuNuo4-Jun-07 2:05 
GeneralRe: Error in reload operator Pin
Chen-XuNuo4-Jun-07 2:07
Chen-XuNuo4-Jun-07 2:07 
AnswerRe: Error in reload operator Pin
Arman S.3-Jun-07 19:52
Arman S.3-Jun-07 19:52 
GeneralRe: Error in reload operator Pin
Chen-XuNuo4-Jun-07 1:03
Chen-XuNuo4-Jun-07 1:03 
GeneralRe: Error in reload operator Pin
David Crow4-Jun-07 4:44
David Crow4-Jun-07 4:44 
QuestionSome questions about Message Queue Pin
GameProfessor3-Jun-07 18:04
GameProfessor3-Jun-07 18:04 
AnswerRe: Some questions about Message Queue Pin
Matthew Faithfull3-Jun-07 21:31
Matthew Faithfull3-Jun-07 21:31 
GeneralRe: Some questions about Message Queue Pin
GameProfessor4-Jun-07 1:31
GameProfessor4-Jun-07 1:31 
GeneralRe: Some questions about Message Queue Pin
Mark Salsbery4-Jun-07 5:20
Mark Salsbery4-Jun-07 5:20 
Questionhow to translate Common Dialog into all kinds of language version? [modified] Pin
Peter, Chan3-Jun-07 17:59
Peter, Chan3-Jun-07 17:59 
QuestionHow to run exe on xp with another account status? Pin
zhongwenjia3-Jun-07 14:55
zhongwenjia3-Jun-07 14:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.