help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Converting MSVC -> gcc -- template errors


From: Julian Mensch
Subject: Converting MSVC -> gcc -- template errors
Date: 20 May 2007 17:53:16 -0700
User-agent: G2/1.0

  Hey, folks,

  I've got a large application which uses several
custom template-based container classes (Array,
etc.) that link with its own memory management.
The app is written in VC++ and is now being
converted to Linux under gcc.

  Now, the template containers are mostly member
variables of other classes. To prevent undefined
externals in VC++, we declared the template
containers with default initial sizes and deltas as
they were used in the program with the code
below:

template Array<Field,10,5>;                       /* Map::Fields */
template Array<hObj,1000,10>;                      /* Map::Things */
template Array<hObj,30,30>;
template Array<hObj,5,5>;
template Array<Status,0,1>;                       /* Creature::Stati
*/
template Array<GroupNode,20,2>;                   /* Registry::Groups
*/
template Array<Object*,10,10>;                    /*
LoadGroup::LoadedObjects */
template Array<uint16,20,20>;                     /* Map::TorchList */
template Array<LimboEntry,20,10>;                 /* Game::Limbo */
template Array<MTerrain,0,10>;                    /* Map::TerraXY */
template Array<TerraRecord,0,5>;                  /* Map::TerraList */
template Array<Annotation,ANNOT_INITIAL_SIZE,20>; /* Module::Annot */
template Array<ModuleRecord,5,5>;                 /* Game::ModFiles */
template Array<uint16,20,20>;                     /* PQueue::Elements
*/
template Array<uint16,200,200>;                     /*
PQueue::Elements */
template Array<hObj,10,20>;                       /* Thing::backRefs
*/

  These declarations cause the templates to be
instantiated with the given template parameters in
the file where they appear.

  gcc chokes on this code, probably because it's not
truly correct C++ practice -- I'm by no means a
template guru. VC++, however, compiles it fine.
The exact error is "expected unqualified-id before ';'
token". When you comment these out, you get many, many
undefined external symbol errors using either
compiler.

  Can anyone here give me a bit of advice (other
than "use STL", which isn't really helpful) to make
the above instantiation of templates into more
legitimate C++ code that gcc will accept?

  If it helps, here is the declaration of the Array class
from the headers; it's very standard stuff:

---------

template<class S, int16 Initial, int16 Delta>
  class Array
  {
    private:
      S *Items;
      uint16 Size, Count;
      void Enlarge();
      void Reduce();
    protected:
      S* _Paren(int16 index);
    public:
      Array();
      ~Array() { if (Items) free(Items); }
      void Serialize(hObj myObj);
      void Set(S&,int16 idx);
      int16 Add(S&);
      int16 Total() { return Count; }
      void Remove(int16 i);
      S*   NewItem();
      void Serialize(Registry &r);
      void Clear() { Count = 0; };
  };



reply via email to

[Prev in Thread] Current Thread [Next in Thread]