PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Problems with GCC

Pejo Software - Per · 23 May 2004, 09:41 UTC
I am trying to port my game to Symbian and to do this I made a small STL implementation. I now have a problem with my basic_string implementation. It works great when I use the MS compiler but GCC doesn't seem to get it.

Here is a code snippet:
Code:
template <class charT, class Traits=char_traits<charT>,class StoragePolicy=SimpleStringStorage<charT,Traits> >
class basic_string :public StoragePolicy
{
public:
typedef size_t size_type;
typedef charT value_type;
typedef charT & reference;
typedef const charT& const_reference;
typedef StoragePolicy::iterator iterator;
typedef StoragePolicy::const_iterator const_iterator;
...
...
};


GCC then gives me the following error:
string:323: `StoragePolicy::iterator' is not a valid declarator
string:323: perhaps you want `typename StoragePolicy::iterator' to make it a type.

So I change to the following:
Code:
template <class charT, class Traits=char_traits<charT>,class StoragePolicy=SimpleStringStorage<charT,Traits> >
class basic_string :public StoragePolicy
{
public:
typename StoragePolicy::iterator;
typename StoragePolicy::reverse_iterator;

typedef size_t size_type;
typedef charT value_type;
typedef charT & reference;
typedef const charT& const_reference;
typedef StoragePolicy::iterator iterator;
typedef StoragePolicy::const_iterator const_iterator;
...
...
};


This gives me the same error though.

Any C++ guru here that can tell me what to do?
I beleive that GCC just isn't capable enough and maybe I shall remove the StoragePolicy solution (STL doesn't use this), but I think it was rather elegant!
Try this:

"typedef typename StoragePolicy::iterator iterator;"
Pejo Software - Per · 23 May 2004, 17:51 UTC
I'll try this later on.
Rigth now I have worked around it by (kind off) removing StoragePolicy but now I have problems with other parts in the code that uses templates. It seems like GCC (Symbian version, derivate of version 2.9) doesn't like templates very much.
Pejo Software - Per · 23 May 2004, 20:05 UTC
It seems like GCC doesn't like me! It just ends with internal compiler error!
I wonder if I in anyway could upgrade to a newer version. Version 2.9 is quite old. Perhaps this isn't the right forum for discussing this, perhaps I shall find a symbian forum.
GCC v3 has been out for ages. Do upgrade.
Pejo Software - Per · 24 May 2004, 09:54 UTC
I am not sure it is possible (without much effort) since a modified version of GCC is used for Symbian.
Pejo Software - Per · 24 May 2004, 21:30 UTC
Thierry I did as you suggested and and it solved all my problems, thanks!. I guess my work around caused the compiler error. It is quite obvious that this is how it shall be done if you think about it.
If I just had done as you said right away I would have saved a lot of time!
I was surprised you were still getting problems. You are supposed to put the typename keyword, otherwise the compiler doesn't know that you are declaring a variable.

In fact, it is VC / EVC that is too permisive/wrong in accepting your code without the "typename" keyword.