[prog] C++ Inheritance
Sue Stones
suzo at bigpond.net.au
Sat May 24 15:34:47 EST 2003
Would someone mind giving me some pointers on the following error message.
I just cant see what is going wrong.
I have 3 files, each befining with a comment block, included below
The output when I attemp to compile the program is below.
make
g++ -o ftest fstest.C
/tmp/cclfc7rJ.o: In function `main':
/tmp/cclfc7rJ.o(.text+0x1a): undefined reference to
`fstream_ext::fstream_ext(int, char const *, int)'
collect2: ld returned 1 exit status
make: *** [fstest] Error 1
A part form anything else it is putting in an extra argument "int" in the
call to the fstream_ext construcotor. Any ideas what is going on here?
/***************************************************
*
* fstream_ext.h the header file for
* fstream_ext which adds fuctionality to the
* standard library class fstream
*
***************************************************/
#include <fstream>
#include <iostream>
class fstream_ext : public fstream {
public:
fstream_ext(){} // default constructor
explicit fstream_ext(const char *filename, openmode mode=in|out);
// constructor
void reset(void); // resets the read pointer to the
// start of the file
void skip(int number); // skips over a number of characters
void position(char *str); // positions the read pointer after a
// given string of characters in the file
private:
const char *_fname;
};
/***************************************************
*
* fstream_ext.C an exention for
* fstream which adds fuctionality to the
* standard library class fstream
*
***************************************************/
#include "fstream_ext.h"
fstream_ext::fstream_ext(const char *filename, openmode mode)
:fstream(filename, mode)
{
strcpy(filename, _fname);
}//constructor
void fstream_ext::reset(void)
{
fstream::close();
fstream::open(_fname);
}//reset
void fstream_ext::skip(int number)
{
}//number
void fstream_ext::position(char *str)
{
}//position
/***************************************************
*
* fstest.C a client to test fstream_ext
*
***************************************************/
#include "fstream_ext.h"
using std::cout;
using std::endl;
int main()
{
fstream_ext filestr("testfile"); // create a file stream assiciated
// with the file 'testfile'
filestr.close();
return 0;
}//main
More information about the Programming
mailing list