0

I am trying to write a wrapper class for the Poco functions that I use.

Here is my code:

//PocoWrapper.h
#include <stdio.h>
#include <Poco/Task.h>
#include <Poco/TaskManager.h>
#include <Poco/ThreadPool.h>

namespace myNamespace{

class ThreadPool : Poco::ThreadPool{};

}

Now if I include PocoWrapper.h in another script, I should be able to use:

myThreadPool = new myNamespace::ThreadPool(1,4);

But This gives the error:

//error: C2661: 'myNamespace::ThreadPool::ThreadPool' : no overloaded function takes 2 arguments

However, if I use:

myThreadPool = new Poco::ThreadPool(1,4);

It compiles fine. Therefore the problem must be that it is not inheriting the default values for the functions from the Poco::ThreadPool Class.

The ThreadPool constructor has default values, so it should be able to be used with only 2 arguments. From the documentation:

ThreadPool(
    int minCapacity = 2,
    int maxCapacity = 16,
    int idleTime = 60,
    int stackSize = 0
);

How can I make my wrapper class work with only two arguments, like the base class does?

I am not using c++11.

Blue7
  • 1,750
  • 4
  • 31
  • 55
  • 1
    Methods are inherited _but_ constructors are a special case. Please, have a look at [SO: Inheriting constructors](https://stackoverflow.com/a/434784/7478597). As this has nothing to do with Poco specifically, it looks like a duplicate. – Scheff's Cat Aug 02 '17 at 08:39
  • Don't you need public inheritance? – danielspaniol Aug 02 '17 at 08:39
  • Possible duplicate of [Inheriting constructors](https://stackoverflow.com/questions/347358/inheriting-constructors) – Scheff's Cat Aug 02 '17 at 08:40

2 Answers2

1

You can inherit the base class's constructors by using their collective name:

namespace Poco {
    struct ThreadPool{
        ThreadPool(int);
        ThreadPool(int,int);
    };
}

namespace myNamespace{

    class ThreadPool : Poco::ThreadPool{
        using Poco::ThreadPool::ThreadPool;  // inherits constructors
    };

}
Richard Hodges
  • 68,278
  • 7
  • 90
  • 142
  • Thanks, but I now get the error.: " Error C2876: Poco::ThreadPool : not all overloads are accessible". How can I only inherit the public constructors? – Blue7 Aug 02 '17 at 08:49
1

The reason is that constructors are not inherited. So, there is no a constructor in ThreadPool class which accepts two arguments.

On the other hand, when you create Poco::ThreadPool class, you are free to use any of its constructors. Note, that according to the documentation, there are two constructors and each of them accepts optional parameters, so there is no need to specify a full list of parameters.

You might use using declaration to "inherit" constructors:

class ThreadPool : Poco::ThreadPool {};
    using Poco::ThreadPool::ThreadPool;
}
Edgar Rokjān
  • 17,245
  • 4
  • 40
  • 67