开发者

How to forward declare the following template class

开发者 https://www.devze.com 2022-12-21 13:07 出处:网络
I try to forward declare concurrent_bounded_queue ; class MyClass { namespace tbb { template<typename T> class cache_aligned_allocator;

I try to forward declare concurrent_bounded_queue ;

class MyClass {
    namespace tbb {
        template<typename T> class cache_aligned_allocator;
        template<class T, class A = cache_aligned_allocator> class concurrent_bounded_queue;
    };

    // I wish to maintain this syntax.
    tbb::concurrent_bounded_queue<std::string>& concurrentBoundedQueue;
}

I get the following error :

error C3203: 'cache_aligned_allocator' : unspecialized class template can't be used as a template argument for template parameter 'A', expected a real type
error C2955: 'tbb::cache_aligned_allocator' : use of class template requires template argument list c:\projects\vitroxreport\src开发者_如何转开发\Executor.h(21) : see declaration of 'tbb::cache_aligned_allocator'

May I know how I can avoid?

Thanks.


Allocator is a template, but second argument of the queue is concrete class. Try this:

class MyClass {
    namespace tbb {
        template<typename T> class cache_aligned_allocator;
        template<class T, class A = cache_aligned_allocator<T> > 
            class concurrent_bounded_queue;
    };

    tbb::concurrent_bounded_queue<std::string>& concurrentBoundedQueue;
};
0

精彩评论

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