开发者

C++ Problem with a class template

Why won't this template compile?

template <class K, class V = Referenced>
class Cache
{
public:
    Cache();
    ...
};

template <class K, class V>
Cache::Cache()   <====  location of compiler error (see 开发者_JAVA技巧below)
{
    ...
}

ERROR error: 'template<class K, class V> class Cache' used without template parameters


You need to specify the template parameters:

template <class K, class V>
Cache<K, V>::Cache()
{
    ...
}


template <class K, class V>
Cache<K,V>::Cache() // Specify the template parameters
{
   //...

}


Try this:

template <class K, class V>
Cache<K, V>::Cache()
{
    ...
}

Notice the template parameters following the class name.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜