The following test code compiles and executes correctly:

class RegExpTest : public Framework
{
   template <class T> int reParseNumbers( std::string, std::set<T>&, double=-1 )
            throw(Exception );
}

template <class T> int RegExpTest::reParseNumbers( std::string s, std::set<T> & numSet, double set_size_limit )
      throw( Exception )
{
  // do some regular expression stuff and return an int 
}

However when I attempt to incorporate this as a standalone inline function in a namespace (and not as part of a class):

namespace StringFunctions
{

template <class T>
      inline int reParseNumbers(   std::string s, 
                                    std::set<T> & numSet, 
                                    const double set_size_limit=-1 )
      throw( StringException );

template <class T> 
      inline int reParseNumbers(   std::string s, 
                                    std::set<T>& numSet, 
                                    const double set_size_limit )
      throw( StringException )
      {
       // do some regular expression stuff and return an int 
      }
}

I get the following error messages:

"StringFunctions.hpp", line 5: Error: Templates can only declare classes or functions.
"StringFunctions.hpp", line 11: Error: Templates can only declare classes or functions.

I've narrowed the problem with the second code example down to the std::set<T> parameter that is being passed. Although the code compiles fine in as part of a class, when it is included as a standalone inline function in a namespace, the compiler chokes on the second std::set<T> parameter with the error message above.

What should I do differently to inline a templated method standalone in a namespace (as opposed to having it as part of a class)?

Any advice would be much appreciated

The problem is that you can have the inline OR the declaration.
You can't have both. So if you delete 5,6,7,8 all isl be fine.
If you wish to define the function outside of the namespace definition then delete lines 10-17.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.