[sclug] C++ Stardate 2214 - Still having pointer & vector problems!
Tim Sutton
t.sutton at reading.ac.uk
Sat Oct 25 09:05:38 UTC 2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi
My apologies if this is getting monotonous, but I always seem to trip up on
the pointer thing :-( I have a filegroup class which is essentially a
collection of filereader objects. FileGroup is designed to iterate through a
number of filereader objects at the same time. My problem is when I try to
assign a new FileReader object to FileGroup, I get a compile error:
filegroup.cpp: In member function `virtual bool
FileGroup::addFileReader(FileReader*, int)':
filegroup.cpp:29: no matching function for call to `std::vector<FileReader,
std::allocator<FileReader> >::push_back(FileReader*&)'
/usr/include/c++/3.2.2/bits/stl_vector.h:492: candidates are: void
std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = FileReader,
_Alloc = std::allocator<FileReader>]
gmake[2]: Leaving directory `/home/aps02ts/dev/cpp/csm_dataprep/csm_dataprep'
I realise I have my pointers & or references screwed up somewhere, but having
tried every sensible permutation I could think of, I am still having no luck.
I have also trawled google and all my c++ books but cant seem to find a
decent example similar to what I am trying to do :-( Can anyone help me? See
code snippets below for more detail.
Many thanks
Tim.
void test()
{
FileGroup *myFileGroup = new FileGroup;
FileReader *myFileReader = new FileReader;
myFileGroup->addFileReader(myFileReader,1);
}
- -------------------------------------------
/**A file group manages a collection of FileReader objects and is used
* to steop through several filereaders simultaneously.
* @author Tim Sutton
*/
class FileGroup {
public:
FileGroup();
virtual ~FileGroup();
/** Add a new file reader object to the filegroup and position the fpos_t at
the start of the data block requested. */
virtual bool addFileReader(FileReader *theFileReader, int theDataBlockNo) ;
private:
std::vector <FileReader> fileReaderVector;
};
- -----------------------------------
#include "filegroup.h"
FileGroup::FileGroup(){
}
FileGroup::~FileGroup(){
}
/** Add a new file reader object to the filegroup and position the
* fpos_t at the start of the data block requested. */
bool FileGroup::addFileReader(FileReader* theFileReader, int theDataBlockNo)
{
//theFileReader->
fileReaderVector.push_back(theFileReader);
}
- -----------------------------------
- --
Tim Sutton
BDWorld Middleware Programmer
- -------------------------------------------------------------------
BiodiversityWorld Project
Centre for Plant Diversity & Systematics
School of Plant Sciences
The University of Reading
Reading, RG66AS, UK
Web : www.bdworld.org
Phone : +44-(0)118-378-6052
Email : t.sutton [at] reading.ac.uk
(email preferred method of correspondence)
- -------------------------------------------------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQE+v1J+Zxb+GYjbYHkRAqbfAKCu4PdoJ7CBxo5lQi4LNYRvDIZCaQCgnINf
ol9bQweTRgJ6ZdDMMzJ6sw0=
=VlQe
-----END PGP SIGNATURE-----
More information about the Sclug
mailing list