Polymorphic inheritance and templates problem.

Started by
3 comments, last by persil 18 years, 6 months ago
Hi, I'm currently working on my VFS and it's working quite fine. It's not 100% complete yet, as many bugs must be still there and a couple of features are incomplete, but the big picture is there. Now I'm trying to make it compile under more than one compiler. I was using MinGW and I've succeeded to compile it with Microsoft's .Net 2003 C++ compiler. Now I'm attempting to compile it with Digital Mars, however, it doesn't like one of my classes, which is at the same time a derived class and a template. Here's an approximation of the classes:

class drive
{
public:
  virtual ~drive();
  // Virtual members and stuff...
  
protected:
  class iterator_;
  friend class iterator_;
  class iterator_
  {
  public:
    virtual ~iterator_();
    virtual void next() = 0;
    // ... Other virtual members ...
  };
  virtual iterator_ * create_iterator_( /* parameters */ ) = 0;
};

drive::~drive()
{
}

drive::iterator_::~iterator_()
{
}

template< class T >
class file_drive : public drive
{
public:
  virtual ~file_drive();
  
protected:
  class iterator_ : public drive::iterator_ // *** Line 34 ***
  {
  public:
    virtual ~iterator_();
    virtual void next();
    // ... Other virtual members ...
  };
  virtual iterator_ * create_iterator_( /* parameters */ );
};

template< class T >
file_drive< T >::~file_drive()
{
}

template< class T >
file_drive< T >::iterator_::~iterator_()
{
}

template< class T > // *** Line 54 ***
void file_drive< T >::iterator_::next()
{
}

template< class T >
typename file_drive< T >::iterator_ * file_drive< T >::create_iterator_()
{
  return 0;
}

struct dpk_properties
{
};

class dpk_drive : public file_drive< dpk_properties >
{
public:
  virtual ~dpk_drive();
};

dpk_drive::~dpk_drive()
{
}

int main()
{
  return 0;
}



With exactly this source code, I can compile with MinGW and VC++, but Digital Mars gives me these 2 error codes: Line 54: Error: 'iterator_' is not a class template. Line 34: Error: member 'drive::iterator_' of class 'drive' is not accessible. What am I doing wrong? Or is it something Digital Mars can't handle? Thanks for the help.
Advertisement

IMHO, if both MinGW and Visual compile your code without any problems, then it's a problem with Digital Mars. Maybe you should check fourth compiler: http://www.comeaucomputing.com/tryitout/ :-)

Btw, which version of the MinGW?
Thanks for the reply.

Well, actually, after much twiddling, I managed to compile the code, but it comes down that, yes, it's Digital Mars that is lacking. The two errors are related to these limitations, unless I'm mistaken:

1. Digital Mars doesn't like template member definition outside of class definition.

2. It doesn't allow protected sub-class to be accessed from derived classes, even though it should. Putting the iterator_ virtual class in the public area of 'drive' "corrected" the problem.

Comeau is online, it feels weird, I'll stick to MinGW. I use the latest version, AFAIK.

Thanks.
Quote:Original post by persil
Comeau is online, it feels weird, I'll stick to MinGW. I use the latest version, AFAIK.


It might feel weird, but if you're trying to guess standards conformance, Comeau is your best choice. It's the most standards-conformant compiler out there. If you don't feel like reading the standard and figuring it out yourself, you would be better off turning to Comeau instead of relying on a poll of the others.
okay, if you say so, it's just that it's the first time I read about it.

I've always heard that MSVC7.1 and MinGW (GNU) were both very good standard conformant compilers. And I've heard about Watcom, Borland, Digital Mars... But not Comeau.

I'll give it a try and copy+paste my example just to see :)

This topic is closed to new replies.

Advertisement