| | |
classes in C++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2005
Posts: 25
Reputation:
Solved Threads: 0
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
and heres my main
/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
C++ Syntax (Toggle Plain Text)
#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
C++ Syntax (Toggle Plain Text)
#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; }
•
•
Join Date: Nov 2004
Posts: 108
Reputation:
Solved Threads: 3
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).
Make a seperate file for your rational or define them in your main file(I wouldn't do this).
Join me on IRC:
Server: irc.daniweb.com
Channel: #C++
Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
Server: irc.daniweb.com
Channel: #C++
Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
•
•
•
•
Originally Posted by prog-bman
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).
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?
![]() |
Similar Threads
- need idea for project using classes and inheritance (C++)
- How do i do chat program using MFC (Microsoft Foundation Classes) and Visual Basic? (Visual Basic 4 / 5 / 6)
- Loading classes from a .jar file (Java)
- Help with Classes (C++)
- Understanding classes (C++)
- Working with objects of different Classes (Java)
- Classes (C++)
- Summer Classes (Geeks' Lounge)
Other Threads in the C++ Forum
- Previous Thread: C++ complete binary tree using an array. Unexpected end file
- Next Thread: Statistical functions in C++/Excel
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets





