0

I have the following class definition and for some reason I cannot define the threadpool inside the class definition itself. It says: syntax error: identifier 'numberofpoolthreads' I tried directly defining it in the class, but it gives me same syntax error, does anyone know why this is?

#include "stdafx.h"
#include <boost/threadpool.hpp>
#include <boost/threadpool/pool.hpp>
#include <boost/threadpool/detail/pool_core.hpp>

typedef boost::threadpool::fifo_pool resolverpool;

class ResolverThreadPoolManager
{
public:
    ResolverThreadPoolManager::ResolverThreadPoolManager(int numberofpoolthreads);
    ResolverThreadPoolManager::~ResolverThreadPoolManager();

    resolverpool p(numberofpoolthreads);

private:
    int numberofpoolthreads;    
};

2 Answers 2

1

This line: resolverpool p(numberofpoolthreads); isn't valid in a class definition. You need a member variable, which you then initialise in the constructor. e.g.:

class ResolverThreadPoolManager
{
public:
    explicit ResolverThreadPoolManager(int numberofpoolthreads);
    ...

private:
    const resolverpool p;
};

ResolverThreadPoolManager::ResolverThreadPoolManager(int numberofpoolthreads)
    : p(numberofpoolthreads)
    {}
Sign up to request clarification or add additional context in comments.

1 Comment

normally you initialize the threadpool like this: boost::threadpool:fifo_pool pool(5), where 5 is the number of threadpool threads. I want this number to be held in a variable, so how would I do this then?
0

In your line
resolverpool p(numberofpoolthreads);
the argument "numberofpoolthreads" is not a type, so this is a malformed declaration. Perhaps
resolverpool p(int numberofpoolthreads);
? I imagine, perhaps incorrectly, that your error message also hints on which line the error occurred, which can help narrow down where in a file an error lies. (Although, typically only indicating "error is on this or some previous line.")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.