Why std :: unary_function does not contain a virtual destructor

I came across a class template std::unary_functionand std::binary_function.

template <class Arg, class Result>
struct unary_function {
    typedef Arg argument_type;
    typedef Result result_type;
};

template <class Arg1, class Arg2, class Result>
struct binary_function {
    typedef Arg1 first_argument_type;
    typedef Arg2 second_argument_type;
    typedef Result result_type;
};

Both can be used as a base class for specific purposes. But there is no virtual destructor in this. One of the reasons that I could guess about is that they are not designed to be polymorphic. i.e

std::unary_function* ptr; 
//intialize it 
//do something
delete ptr;

But if this is the case, there should not be a destructor with protectedan access specifier for the compiler to violate any attempt to do this.

+4
source share
3 answers

++ "" - , , , . , . , unary_function, binary_function, iterator .., , . .

, " " , . . ​​ .

- ... , . , - ( typedef s).

, unary_function, binary_function , iterator . . , ++ Mixins ..

+7

std::unary_function std::binary_function : typedefs .

++, , - .

. , :

void foo(std::unary_function* f)
{
     delete f; // illegal
}

, , ++ 11 (. N3145)

+3

, (, std::iterator<...>) , , , , STL, , . , , , , - , "--". , .

STL , STL . , , , , - . , .

- ++ 11 ( , ), , "" ( , ).

+2

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


All Articles