This is the code for a fractions program that is to add and subtract(i know it does not subtract yet)
I am having error messages that I dont understand.

``````// File Fraction.h

#ifndef FRACTION_H
#define hbg_cmpsc122

#include <iostream>
using namespace std;

namespace hbg_cmpsc122
{

class Fraction
{
private:

int num;
int denom;

public:

Fraction();
Fraction(int n, int d);
int setNum(int n);
int setDenom(int d);
void print();

Fraction sub_func (Fraction b);

};
}

#endif``````
``````// File fraction.cxx

#include "fraction.h"
#include <iostream>
#include <cstdlib>
#include <cassert>

using namespace std;

namespace hbg_cmpsc122
{

Fraction::Fraction()
{
num = 0;
denom = 1;
}

Fraction::Fraction(int n, int d)
{
num = n;
denom = d;
}

int Fraction::setNum(int )
{

return num;
}

int Fraction::setDenom(int )
{

return denom;
}

void Fraction::print()
{
// displays fraction on screen
cout << "Fraction: " << num << "/" << denom << endl;
}

{

if (a.denom =! a.setDenom())
{
answer.denom = a.denom * a.setDenom() + (a.setNum() * a.denom);
answer.num = (a.num * a.setNum())+(a.setNum() * a.denom);
}
else
{
}

}

}``````
``````// File Main.cpp

#include <iostream>
#include <cstdlib>
#include "fraction.h"

using namespace std;

using hbg_cmpsc122::Fractions;

int main()
{

fraction f1(3,2), f2(4,5), f3, f4;

cout <<endl << "Fraction f1 is: ";
f1.print();

cout <<endl << "Fraction f2 is: ";
f2.print();

cout << endl << endl << "The sum of the fractions is ";
f3.print;

return 0;
}``````

This is the code for a fractions program that is to add and subtract.
I am having error messages that I dont understand.

fraction.cxx: In member function `<unnamed>::Fraction <unnamed>::Fraction::add_func(<unnamed>::Fraction)':
fraction.cxx:40: error: `((<unnamed>::Fraction*)this)-><unnamed>::Fraction::denom' cannot be used as a function
fraction.cxx:42: error: no matching function for call to `<unnamed>::Fraction::setDenom()'
fraction.h:25: note: candidates are: int <unnamed>::Fraction::setDenom(int)
fraction.cxx:42: error: no matching function for call to `<unnamed>::Fraction::setNum()'
fraction.h:24: note: candidates are: int <unnamed>::Fraction::setNum(int)
fraction.cxx:43: error: no matching function for call to `<unnamed>::Fraction::setNum()'
fraction.h:24: note: candidates are: int <unnamed>::Fraction::setNum(int)
fraction.cxx:43: error: no matching function for call to `<unnamed>::Fraction::setNum()'
fraction.h:24: note: candidates are: int <unnamed>::Fraction::setNum(int)
fraction.cxx:50: error: no matching function for call to `<unnamed>::Fraction::setNum()'

>>using hbg_cmpsc122::Fractions;

Fractions is not in namespace hbg_cmpsc122 because you have misspelled the class name. Pay closer attention to spelling and capitalization -- fraction is not the same thing as Fraction.

What compiler are you using? I'm on MS-Windows using vc++ 2010 Express and I get lots of error messages and warnings.

Also, delete line 4 in Fractions.h.

I am using g++

I don't use that compiler, but I know there are flags that will make it spit out more warnings and errors.

Two quick comments, AD is correct that you should have deleted line 4 in Fraction.h, [and that you have misspelled fractions in main()] (what it does is define the symbol hbg_cmpsc122 as and empty value. Therefore when you write `namespace hbg_cmpsc122 {` you have effectively writen `namespace {` .

This is why you have all the error messages to the unnamed namespace.

The normal include file guard, is to write this

``````#ifndef FRACTION_H
#define FRACTION_H

So perhaps it would be better to change line 4 of Fraction.h to `#define FRACTION_H` .