Is it possible to inherit operator () in C ++?

I am writing some hash function examples for hash_map. If I use hash_map defined by my compiler, I need to define Comparer in Hasher. I know that it is better to use tr1 :: unordered_map, but in my application it is important to set the minimum number of large buckets and determine the average value of bucket_size - a condition for growth.

So, I would like to implement a controller in the base class Foo and inherit it in other hashers such as Bar.

class Foo
{
public:
    Foo(const SeedParam& dim);
    Foo(const Foo& src);
    Foo& operator = (const Foo& src);
    virtual bool operator ()(const Index2& ind1, const Index2& ind2) const;
    size_t operator() (const Index2& ind) const;

    enum
    {
        bucket_size = 4,
        min_buckets = 32768,
    };
protected:
    SeedParam _dim;
    const hash_compare<unsigned long long> _stdHasher;
};

class Bar: public Foo
{
public:
    Bar(const SeedParam& dim);
    size_t operator() (const Index2& ind) const;
};

But compilers say that β€œthe term does not evaluate a function that takes two arguments” when compiling such code in hash_map:

if (!this->comp(this->_Kfn(*_Where), _Keyval))

So can operator () be inherited? What is wrong with my classes?

+3
2

- , ( ) .

( () ), , . , .

() Bar, , Foo .

,

using Foo::operator();

.

+4

, , . Foo 2 operator(), StdDimHasher ( , Bar) operator(). , args 2 args, arg.

my2c

+1

Source: https://habr.com/ru/post/1736456/


All Articles