Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > expected constructor, destructor, or type conversion before

Reply
Thread Tools

expected constructor, destructor, or type conversion before

 
 
mhubbard mhubbard is offline
Junior Member
Join Date: Apr 2008
Posts: 1
 
      04-04-2008
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 {
:IR* 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:ointer 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>:perator++()
{
// limiting doesn't need to happen here: it happens in operator==()
++base;
++count;

return *this;
}

template <typename T>
bool ipssend::LimitedIterator<T>: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>: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:irectoryOpenError:irectoryOpenError(in t err)
: runtime_error("Error opening directory"), _error(err)
{
/* nothing */
}

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

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

namespace {
const unsigned long INVALID_INO = 0;
}

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

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

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

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

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

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

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

bool ipssend:irectoryIterator:perator==(const ipssend:irectoryIterator& 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:irectoryIterator:perator*() const
{
return ent;
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error: expected constructor, destructor or type conversion before '(' token suse Software 0 03-09-2009 03:25 AM
error: expected constructor, destructor, or type conversion before '<' token amitmool@gmail.com C++ 5 11-05-2007 01:56 PM
Expected constructor, destructor or type conversion before... algatt C++ 2 07-19-2007 07:45 PM
"expected constructor, destructor, or type conversion before '->' token" using a Singleton Damien C++ 5 12-13-2006 12:39 AM
expected constructor, destructor, or type conversion before '*' Preben C++ 6 09-20-2006 07:15 PM



Advertisments