expected constructor, destructor, or type conversion before


Joined
Apr 4, 2008
Messages
1
Reaction score
0
Hello - this is my first post here. I have inherited some (seemingly overly)complex c++ template code that I just cannot seem to get to work. The code compiled fine under gcc 2.95, but I can't get it to go under gcc 4.1.2. It's a lot to ask for anyone to delve into this thing, but if anyone is willing, I would be most greatful.

the error is : diriter.H:158: error: expected constructor, destructor, or type conversion before 'ipssend'

Here is diriter.H with a comment right before line 158 which says: BELOW IS LINE 158. After that will be diriter.C

#ifndef __DIRITER_H__
#define __DIRITER_H__

#include <stdexcept>
#include <iterator>
#include <sys/types.h>
#include <dirent.h>

namespace ipssend {

class DirectoryOpenError : public std::runtime_error {
int _error;
public:
DirectoryOpenError(int err);
int errorCode() const;
};

class DirectoryIterator {
public:
typedef std::input_iterator_tag iterator_category;
typedef ::dirent value_type;
typedef ptrdiff_t difference_type;
typedef ::dirent* pointer;
typedef ::dirent& reference;
private:
struct _dirref {
::DIR* dir;
int refcount;
_dirref(const char*);
~_dirref();
} * dirref;
::dirent ent;
public:
DirectoryIterator();
DirectoryIterator(const DirectoryIterator& i);
DirectoryIterator(const char* _dirname);
~DirectoryIterator();

DirectoryIterator& operator++();
bool operator==(const DirectoryIterator&) const;
const ::dirent& operator*() const;

inline bool operator!=(const DirectoryIterator& i) const
{ return !operator==(i); }

};

template <typename T>
class LimitedIterator {
public:
typedef typename T::iterator_category iterator_category;
typedef typename T::value_type value_type;
typedef typename T::difference_type difference_type;
typedef typename T::pointer pointer;
typedef typename T::reference reference;
private:
T base;
int limit;
int icount;
int& count;
public:
inline LimitedIterator();
inline LimitedIterator(const LimitedIterator<T>& i);
inline LimitedIterator(const T& _base, int _limit);
inline LimitedIterator(const T& _base);

// update an external count instead of the internal one.
// WARNING: if you iterate over a LimitedIterator, your
// external counter will increment for every ++, *including
// the final one past the end of the container*! As a result,
// if you use this constructor, you probably want to decrement
// your counter immediately after any iteration.
inline LimitedIterator(const T& _base, int _limit, int& _count);

inline LimitedIterator<T>& operator++();
inline bool operator==(const LimitedIterator<T>&) const;
inline reference operator*() const;

inline bool operator!=(const LimitedIterator<T>& i) const
{ return !operator==(i); }

inline int entriesSeen() const;
};

// convenience functions to construct appropriate LI's to wrap
// other iterators
template <typename T>
inline LimitedIterator<T> limit(const T& base);

template <typename T>
inline LimitedIterator<T> limit(const T& base, int limit);

template <typename T>
inline LimitedIterator<T> limit(const T& base, int limit, int& count);

}

template <typename T>
ipssend::LimitedIterator<T>::LimitedIterator()
: base(), limit(-1), icount(0), count(icount)
{
// nothing
}

template <typename T>
ipssend::LimitedIterator<T>::LimitedIterator(const ipssend::LimitedIterator<T>& i)
: base(i.base), limit(i.limit), icount(i.icount), count(i.count)
{
// nothing
}

template <typename T>
ipssend::LimitedIterator<T>::LimitedIterator(const T& _base, int _limit)
: base(_base), limit(_limit), icount(0), count(icount)
{
++count;
}

template <typename T>
ipssend::LimitedIterator<T>::LimitedIterator(const T& _base)
: base(_base), limit(-1), icount(0), count(icount)
{
++count;
}

template <typename T>
ipssend::LimitedIterator<T>::LimitedIterator(const T& _base, int _limit, int& _count)
: base(_base), limit(_limit), icount(0), count(_count)
{
++count;
}

template <typename T>
ipssend::LimitedIterator<T>& ipssend::LimitedIterator<T>::eek:perator++()
{
// limiting doesn't need to happen here: it happens in operator==()
++base;
++count;

return *this;
}

template <typename T>
bool ipssend::LimitedIterator<T>::eek:perator==(const ipssend::LimitedIterator<T>& i) const
{
// LI's at the end of their iteration are all the same
if ((count > limit) && (i.count > i.limit))
return true;

// i'm not sure why i left limit out of this check; it just feels
// right. as of this 20040206 the only thing that really matters is
// the "end of iteration" check above since real LI's are only ever
// compared to default-constructed ones
return (base == i.base);
}

template <typename T>
//BELOW IS LINE 158
ipssend::LimitedIterator<T>::reference ipssend::LimitedIterator<T>::eek:perator*() const
{
return *base;
}

template <typename T>
int ipssend::LimitedIterator<T>::entriesSeen() const
{
return count;
}

template <typename T>
ipssend::LimitedIterator<T> ipssend::limit(const T& base)
{ return LimitedIterator<T>(base); }

template <typename T>
ipssend::LimitedIterator<T> ipssend::limit(const T& base, int limit)
{ return LimitedIterator<T>(base, limit); }

template <typename T>
ipssend::LimitedIterator<T> ipssend::limit(const T& base, int limit, int& count)
{ return LimitedIterator<T>(base, limit, count); }

#endif // __DIRITER_H__

AND HERE IS DIRITER.C
#include "diriter.H"
#include <cstring>
#include <unistd.h>
#include <errno.h>

/////////////////////////
// DirectoryOpenError
/////////////////////////

ipssend::DirectoryOpenError::DirectoryOpenError(int err)
: runtime_error("Error opening directory"), _error(err)
{
/* nothing */
}

int ipssend::DirectoryOpenError::errorCode() const
{
return _error;
}

//////////////////////////////
// DirectoryIterator
//////////////////////////////

namespace {
const unsigned long INVALID_INO = 0;
}

ipssend::DirectoryIterator::_dirref::_dirref(const char *_dirname)
: dir:):eek:pendir(_dirname)), refcount(1)
{
if (dir == 0)
throw DirectoryOpenError(errno);
}

ipssend::DirectoryIterator::_dirref::~_dirref()
{
if (dir)
::closedir(dir);
}

ipssend::DirectoryIterator::DirectoryIterator()
: dirref(0), ent()
{
// nothing
}

ipssend::DirectoryIterator::DirectoryIterator(const ipssend::DirectoryIterator& i)
: dirref(i.dirref), ent(i.ent)
{
if (dirref != 0)
dirref->refcount++;
}

ipssend::DirectoryIterator::DirectoryIterator(const char* _dirname)
: dirref(new _dirref(_dirname)), ent()
{
ent.d_ino = INVALID_INO;
operator++();
}

ipssend::DirectoryIterator::~DirectoryIterator()
{
if ((dirref != 0) && (--dirref->refcount == 0))
delete dirref;
}

ipssend::DirectoryIterator& ipssend::DirectoryIterator::eek:perator++()
{
::dirent* e = ::readdir(dirref->dir);
if (e == 0)
ent.d_ino = INVALID_INO;
else
ent = *e;
return *this;
}

bool ipssend::DirectoryIterator::eek:perator==(const ipssend::DirectoryIterator& i) const
{
// DI's at the end of their iteration are all the same
if ((ent.d_ino == INVALID_INO) && (i.ent.d_ino == INVALID_INO))
return true;

if ( (dirref == i.dirref) && (dirref != 0) &&
(ent.d_ino == i.ent.d_ino) &&
(ent.d_off == i.ent.d_off) &&
(ent.d_reclen == i.ent.d_reclen) &&
(ent.d_type == i.ent.d_type) &&
:):memcmp(ent.d_name, i.ent.d_name, ent.d_reclen) == 0))
return true;
return false;
}

const ::dirent& ipssend::DirectoryIterator::eek:perator*() const
{
return ent;
}
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top