1

I have a piece of templatised C++ code that compiles fine on Visual Studio 2010, but does not compile on Linux GCC. The code looks fine to me, so my question is: what am I doing wrong here?

This is the code that gives the error (I removed all the irrelevant stuff to get just the problematic part):

class CaseInsensitiveCompare
{
public:
    bool operator() (const RString& first, const RString& second) const;
};

template <typename T>
T CombinedValue<T>::getUpgradedSettingValue(const T& defaultValue, const UpgradeList& upgrades, const RString& className) const
{
    std::map<RString, CombinedSetting<T>, CaseInsensitiveCompare> myMap;
    std::map<RString, CombinedSetting<T>, CaseInsensitiveCompare>::iterator myIter;
}

This compiles and functions just fine, but gives a compile error on GCC on Linux. The error I get from the compiler is that there should be a ; before myIter. So the weird thing is that the line with myMap is fine, but the line with myIter is not. If I remove the line with myMap, I still get the exact same issue.

What am I doing wrong here? My current hunch is that this is an error in the GCC compiler itself, but if that is the case: how can I work around that?

Oogst
  • 358
  • 2
  • 14
  • 2
    try `typename std::map, CaseInsensitiveCompare>::iterator myIter;`. – user1095108 Oct 22 '13 at 11:42
  • Oh and by the way, when posting a question regarding compilation/linker errors, please also include the complete and unedited error log in the question. – Some programmer dude Oct 22 '13 at 11:46
  • 1
    IOW, the custom predicate has nothing to do with it. The usual advice would have helped here, too: Simplify the problem until it goes away, compare those versions to see what fixed it, if there's still a question then post both versions. – MSalters Oct 22 '13 at 11:48
  • Adding typename indeed fixed it. Thanks for the quick reply! And thanks for the link, Joachim! I didn't know how the typename thing worked, seems like Visual C++ allows for more than the standard in this regard, resulting in me as a Windows user not knowing it. Interesting read! :) – Oogst Oct 22 '13 at 12:24

0 Answers0