lundi 28 août 2017

Forward declaration mess

I am creating a multithreaded class method that needs to call 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){
...
}

Now when I try to compile this with compute defined after MyClass, Me::MyClass is not known in the first definition of compute. When I delete the first declaration, compute will not be known when creating the thread?

How can I resolve this catch 22?

error: use of undeclared identifier 'Me'

Aucun commentaire:

Enregistrer un commentaire