alright, so i have two files now, main.cpp, and Rationall.h, when i compiled my code it gave me this....
/tmp/ccyeOf6F.o(.text+0x1a6): In function `main':
: undefined reference to `rational::~rational [in-charge]()'
/tmp/ccyeOf6F.o(.text+0x1c4): In function `main':
: undefined reference to `rational::~rational [in-charge]()'
collect2: ld returned 1 exit status

this is my code......i dont see how its undefined.

this is Rationall.h

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

class rational {

public:
rational(); 
~rational(); 
int setrat( int x, int y); 
int getnum(); 
int getdenom(); 


private:

int numerator;
int denominator;


}; // end of rational class

rational::rational() 
{
numerator = 1;
denominator = 1;
} 
int rational::setrat( int x, int y) 
{
numerator = x;
denominator = y; 
} 
int rational::getnum() 
{
return (numerator);
} 
int rational::getdenom() 
{
return (denominator);
}

and heres my main

#include "Rationall.h"

int main()
{
using namespace std;
int x, y;
rational rationl; 

cout << "Enter in a fraction" << endl;
cout << "Enter in the numerator" << endl;
cin >> x;
cout << "Enter in the denominator" << endl;
cin >> y;

rationl.setrat( x, y );

cout << "The fraction: " << endl;
cout << rationl.getnum() << rationl.getdenom() << endl;

return 0; 
}

Recommended Answers

All 5 Replies

You don't define your function in headers because headers don't get compiled.
Make a seperate file for your rational or define them in your main file(I wouldn't do this).

You don't define your function in headers because headers don't get compiled.
Make a seperate file for your rational or define them in your main file(I wouldn't do this).

What are you talking about? U can define functions in headers if u want to. Now if it's a good practice or not is a different issue. Headers can now be precompiled as far as i know.

To seeplusplus:
try to comment out ur destructor in the definition of ur rational class like this:
//~rational();
That helped me compile ur code without any errors. There were a few warnings though, like ur setrat() function should return an int.
As far as i can recall u sought help for this in another thread, why did u start a new one?

oh i started a new thread because people started fighting in the last one and they ended up closing it. thanks for the help guys.

oh i started a new thread because people started fighting in the last one and they ended up closing it. thanks for the help guys.

Yeah right! I think i rem something like that :lol:

Hey
Did u remeber to add ratinall to your project(Add to project)?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.