Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

first time using my own class...got compile error on mem. func. def.

Status
Not open for further replies.

tinycities

Programmer
Oct 31, 2000
6
US
Hi This program preforms various types of arithmeitc on rational #s, but does not divide the fractions into whole #s. I wrote a class called Rational and created several memb. functions. When I attempt to define my print function I get a compile error. I have pasted the code and error below. Do you know what's up with this? Thanks!

P.S.
I decided to include the previous function def. which is the default constructor(Rational::Rational()), just in case the compiler was off by one line.

Rational::Rational()
{
numer = 0;
denom = 1;
}

void Rational print(ostream& out_stream)
{
out_stream << numer << &quot;/&quot; << denom;
}

Info :Building...
Info :Compiling C:\BC5\BIN\assn7.cpp
Error: assn7.cpp(87,20):Size of 'Rational' is unknown or zero
Error: assn7.cpp(87,20):Declaration syntax error
 
If you are defining the print function outside the class definition as I think you are doing, then I believe you need the scope resolution operator:
Code:
void Rational::print(blah) {
blah blah
}

Hope is a glass of air...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top