Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Templated class method definition syntax

Tags:

c++

templates

Class definition:

template<class K, class V,
         unsigned hashFunc(const K&),
         int compFunc(const K&,const K&)=&_compFunc<K> > class X {};

I want to define a class method outside of the class code block. like so:

template<class K, class V,
         unsigned hashFunc(const K&),
         int compFunc(const K&,const K&)=&_compFunc<K> >
X<K, V, hashFunc, compFunc>::X() { }

g++ v.4.4.3 returns

error: default argument for template parameter for class enclosing ‘X::X()’

Why is the compiler complaining and how can i make it work?

like image 220
Juliusz Avatar asked Jan 22 '23 01:01

Juliusz


1 Answers

You didn't declare or define a constructor for X. In addition, you had repeated the default template parameters in your attempted X::X definition.

Here's the fixed code, main-ified:

template<class K, class V,
         unsigned hashFunc(const K&),
         int compFunc(const K&,const K&)=&_compFunc<K> > 
class X 
{ 
    X();
};

template<class K, class V,
         unsigned hashFunc(const K&),
         int compFunc(const K&,const K&) >
X<K, V, hashFunc, compFunc>::X() { }

int main()
{
}
like image 86
John Dibling Avatar answered Feb 01 '23 14:02

John Dibling