This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: "default template arguments may not be used in function templates"
- From: Travis Spencer <travislspencer at gmail dot com>
- To: Vincent Torri <Vincent dot Torri at iecn dot u-nancy dot fr>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 4 Jul 2005 11:52:15 -0700
- Subject: Re: "default template arguments may not be used in function templates"
- References: <Pine.LNX.4.51.0507041829480.21345@cartan.iecn.u-nancy.fr>
- Reply-to: Travis Spencer <travislspencer at gmail dot com>
On 7/4/05, Vincent Torri <Vincent.Torri@iecn.u-nancy.fr> wrote:
>
> Hello,
Hey, Vincent.
> I have the following class:
>
> template <typename T, typename Synchronizer = synchronizer::None, typename
> Creator = T * (*)()>
> class value_cache
> {
> ***
>
> public: //interface
>
> boost::shared_ptr<T> Get() const
> {
> Synchronizer synchronizer();
>
> ***
> ***
> }
> };
>
> But gcc reports this error message at compile time:
>
> "default template arguments may not be used in function templates"
>
> for the declaration of synchronizer().
>
> I use gcc 3.3.4
You can't use the default arguments in the function declaration (see
http://tinyurl.com/bvnbx). To get around this, declare the class
methods in the header file like normal, but define them after the
class declaration (in the same header file) kinda like this:
// -*- mode: c++ -*-
// value_cache.h
#include <boost/shared_ptr.hpp>
class synchronizer {
class None { };
};
template <typename T, typename Synchronizer = synchronizer::None,
typename Creator = T * (*)() >
class value_cache
{
public:
typedef boost::shared_ptr<T> SharedPtr;
SharedPtr Get() const;
};
#define ValueCache value_cache<class T, class Synchronizer, class Creator>
inline ValueCache::SharedPtr ValueCache::Get() const
{
Synchronizer synchronizer();
}
HTH.
--
Regards,
Travis Spencer
Portland, OR USA