如何转发声明以下模板类

时间:2010-02-26 02:35:25

标签: c++

我尝试转发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;
}

我收到以下错误:

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'

我可以知道如何避免吗?

感谢。

1 个答案:

答案 0 :(得分:5)

Allocator是一个模板,但队列的第二个参数是具体类。试试这个:

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;
};