hello all,
I am one of millions who is new to C++.. I am writing this program about rational numbers and stuck here, I just cant figure where is the prob.. I already searched almost every c++ tutorial but still I am just lost... When try to execute the prog I got errors like:
--------------------Configuration: MyRationalNumber - Win32 Debug--------------------
Compiling...
RationalNumbers.cpp
rationalnumbers.cpp(43) : error C2248: 'num' : cannot access private member declared in class 'RationalNumbers'
rationalnumbers.h(12) : see declaration of 'num'
rationalnumbers.cpp(43) : error C2248: 'den' : cannot access private member declared in class 'RationalNumbers'
rationalnumbers.h(13) : see declaration of 'den'
m_RationalNumbers.cpp
Error executing cl.exe.

MyRationalNumber.exe - 2 error(s), 0 warning(s)

Can you look at my code and tell me the prob?PLEASE...

// Class declaration

#ifndef RATIONALNUMBERS_H
#define RATIONALNUMBERS_H
#include<iostream>
using namespace std;


class RationalNumbers{

friend ostream& operator<<(ostream &os, const RationalNumbers &f);
private:
int num;
int den;

public:
RationalNumbers();
RationalNumbers(int n,int d);
RationalNumbers operator+(RationalNumbers f);
RationalNumbers operator-(RationalNumbers f);
int getLCD(int,int);

};

#endif //RATIONALNUMBERS_H

======================================
Here is my class definition
======================================
#include"RationalNumbers.h"
#include<iostream>
using namespace std;

RationalNumbers::RationalNumbers(){
num = 1;
den = 1;
}

RationalNumbers::RationalNumbers(int n,int d){
num = n;
//check if denominator is not zero
if(d)
den = d;
else{
cout << "Invalid denominator for "<< this << "... Setting denominator to 1." << endl;
den = 1;
}
}

RationalNumbers RationalNumbers:perator +(RationalNumbers f){
RationalNumbers F;
int lcd = F.getLCD(F.den,f.den);
F.num = lcd * num + lcd * f.num;
F.den = lcd;
return F;
}

int RationalNumbers::getLCD(int d1, int d2){
int temp, den1,den2;
den1 = d1;
den2 = d2;
//loop until value second denominator is becomes zero
while(d2){
temp = d2;
d2 = d1 % d2;
d1 = d2;
}
return (den1 * den2 / d1);
}

ostream &operator<<(ostream & os, const RationalNumbers &f){
os << f.num << "/" << f.den;
return os;
}

=================================================
main functions
=================================================
#include"RationalNumbers.h"
#include<iostream>
using namespace std;

int main(){
RationalNumbers A(1,2);
cout << A;
cout << endl;
return 0;
}

Just trying to display Rational Number A, I am not still done with the quarter of the code and I am already stuck..... 8(