我正在创建一个多线程类方法,需要调用compute
。转发声明混乱
void compute(const Me::MyClass<T>& c1, Me:: MyClass<T>& target,std::size_t start);
namespace Me{
template<typename T> class MyClass{
computeMultiThreaded(){
MyClass<T> target = MyClass();
std::size_t n_threads = std::thread::hardware_concurrency();
std::vector<std::tuple<std::size_t, std::size_t>> parts = split_job(n_threads, number_jobs);
std::vector<std::thread> threads;
for (std::size_t ti = 0; ti < n_threads; ti++)
{
// , parts[ti], minCol, this, m2, returnMatrix));
threads.push_back(std::thread(compute,parts[ti]));
}
}
}
}
void compute(const Me::MyClass<T>& c1, Me:: MyClass<T>& target,std::size_t start){
...
}
现在,当我尝试compute
定义MyClass
后,Me::MyClass
是不是在compute
第一个定义称为编译此。当我删除第一个声明时,创建线程时不会知道compute
?
我该如何解决这个问题22?
error: use of undeclared identifier 'Me'
是否 使用Me :: MyClass; 有帮助吗? – tpdi
这是一个大型项目的简化示例... –
是的,因为在声明它之前使用了'Me'。所以命名空间必须在之前声明。 – Raindrop7