C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-27-2008, 10:00 AM   #1
Registered User
 
Join Date: Oct 2008
Posts: 3
inline templated class method as standalone function in namespace

The following test code compiles and executes correctly:

Code:
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):

Code:
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 second std::set<T> parameter that is being passed. Although the code compiles fine as part of my test class, when it is included as a standalone inline'd 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
monikersupreme is offline   Reply With Quote
Old 10-27-2008, 10:21 AM   #2
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,492
The code compiles fine, if <string> and <set> are included and StringException is declared. What compiler are you using?

By the way, throw specifications are a misfeature and do more harm than good. Get rid of them.
__________________
All the buzzt!
CornedBee

"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
CornedBee is offline   Reply With Quote
Old 10-27-2008, 11:57 AM   #3
Registered User
 
Join Date: Oct 2008
Posts: 3
Thanks for the response...

Quote:
Originally Posted by CornedBee View Post
The code compiles fine, if <string> and <set> are included and StringException is declared. What compiler are you using?
CC reports back to me the following version:

Sun C++ 5.9 SunOS_sparc Patch 124863-01 2007/07/25

I guess I'm off to see if there is any documented compiler bug relevant to this issue...
monikersupreme is offline   Reply With Quote
Old 10-28-2008, 11:27 AM   #4
Registered User
 
Join Date: Oct 2008
Posts: 3
Quote:
Originally Posted by CornedBee View Post
By the way, throw specifications are a misfeature and do more harm than good. Get rid of them.
Also, in a nutshell, what is the argument against throw(...)?
monikersupreme is offline   Reply With Quote
Old 10-28-2008, 11:38 AM   #5
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,492
http://www.boost.org/development/req...-specification
__________________
All the buzzt!
CornedBee

"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
CornedBee is offline   Reply With Quote
Reply

Tags
inline, parameter, template

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting an error with OpenGL: collect2: ld returned 1 exit status Lorgon Jortle C++ Programming 6 05-08-2009 08:18 PM
Game Pointer Trouble? Drahcir C Programming 8 02-04-2006 02:53 AM
Post... maxorator C++ Programming 12 10-11-2005 08:39 AM
class errors romeoz C++ Programming 3 09-16-2003 07:57 PM
Predeclaration of template class in namespace unregistred C++ Programming 0 05-30-2003 03:52 AM


All times are GMT -6. The time now is 05:41 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22