2017-08-31 36 views
0

我完全无法解决以下编译错误:冲突的声明类型/值不匹配

#include <iostream> 
#include <boost/lockfree/queue.hpp> 

class C 
{ 
public: 
static int size; 
}; 

int C::size = 10; 

template <class temp> 
class B: public temp 
{ 
class A 
{ 
public: 

    static A pool[temp::size]; 

    static boost::lockfree::queue<A*> mpool; 

    static bool firstTime; 

}; 
public: 
    void show() { std::cout << "Called Show" << std::endl; } 
}; 

template <class temp> 
bool B<temp>::A::firstTime = true; 

template <class temp> 
typename B<temp>::A B<temp>::A::pool[temp::size]; 

template <class temp> 
boost::lockfree::queue<B<temp>::A*> B<temp>::A::mpool(temp::size); 

int main() 
{ 
B<C> d; 
d.show(); 
} 

它指出以下错误 - 我想努力,但未能解决问题 - 帮助需要:

test11.cpp:37:39: error: type/value mismatch at argument 1 in template parameter list for 'template<class T, class A0, class A1, class A2> class boost::lockfree::queue' 
    boost::lockfree::queue<B<temp>::A*> B<temp>::A::mpool(temp::size); 
            ^
test11.cpp:37:39: error: expected a type, got '(B<temp>::A * <expression error>)' 
test11.cpp:37:58: error: invalid type in declaration before '(' token 
    boost::lockfree::queue<B<temp>::A*> B<temp>::A::mpool(temp::size); 
                 ^
test11.cpp:37:58: error: conflicting declaration 'int B<temp>::A::mpool' 
test11.cpp:21:40: note: previous declaration as 'boost::lockfree::queue<B<temp>::A*> B<temp>::A::mpool' 
     static boost::lockfree::queue<A*> mpool; 
             ^
test11.cpp:37:58: error: declaration of 'boost::lockfree::queue<B<temp>::A*> B<temp>::A::mpool' outside of class is not definition [-fpermissive] 
    boost::lockfree::queue<B<temp>::A*> B<temp>::A::mpool(temp::size); 
+0

我添加了typename并尝试了,但是在编译过程中我仍然得到相同的错误 – Prakash

+0

您能否编辑您的问题以包含'typename'关键字,并显示出现的错误。我的猜测是你把它放在了错误的地方。 –

+0

谢谢 - :: A *>固定它,但我完全不明白如何? – Prakash

回答

0

这里你缺少一个类型名称声明。

template<class T> boost::lockfree::queue<typename B<T>::A*> B<T>::A::mpool(T::size);

这一点并不明显B<T>::A是一个类型名。