如何转发声明以下模板类

Che*_*eng 2 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;
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

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'
Run Code Online (Sandbox Code Playgroud)

我可以知道如何避免吗?

谢谢.

Nik*_*sov 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;
};
Run Code Online (Sandbox Code Playgroud)