Jump to content
  • Advertisement
Sign in to follow this  
persil

Polymorphic inheritance and templates problem.

This topic is 4667 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!