开发者

C++ Problem with a class template

开发者 https://www.devze.com 2023-03-10 09:47 出处:网络
Why won\'t this template compile? template <class K, class V = Referenced> class Cache { public: Cache();

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

精彩评论

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