Вопрос по c++, stl – Расширение стандартной библиотеки C ++ по наследству?

51

Error: User Rate Limit Exceededstd::vectorError: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceededstd::exception.

Error: User Rate Limit Exceeded

Are there any other Standard Library classes which are intended to be derived from?

If one does derive from a Standard Library class such as std::exception, is one bound by the interface described in the ISO Standard? For example, would a program which used an exception class who's what() member function did not return a NTBS (say it returned a null pointer) be standard conforming?

Ваш Ответ

10   ответов
17

Error: User Rate Limit Exceeded

1

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceededclass CfgValueError: User Rate Limit Exceeded"TODO: remove inheritance from std::string"Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceededmany differentError: User Rate Limit Exceededit is just extremely handyError: User Rate Limit Exceeded

class CfgValue : public std::string {
public:
    ...
    CfgValue( const int i ) : std::string() { SetInteger(i); }
    ...
    void SetInteger( int i );
    ...
    int GetInteger() const;
    ...
    operator std::wstring() { return utf8_to_ucs16(*this); }
    operator std::wstring() const { return utf8_to_ucs16(*this); }
    ...
};
1

Error: User Rate Limit Exceededthrow()Error: User Rate Limit Exceeded

3

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

7

Error: User Rate Limit Exceeded

The library can be extended by a C++ program. Each clause, as applicable, describes the requirements that such extensions must meet. Such extensions are generally one of the following:

  • Template arguments
  • Derived classes
  • Containers, iterators, and/or algorithms that meet an interface convention

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

  • 17.1.15 "required behavior" covers replacement (operator new, etc.) and handler functions (terminate handlers, etc.) and throws all non-compliant behavior into UB-land.
  • 17.4.3.6/1: "In certain cases (replacement functions, handler functions, operations on types used to instantiate standard library template components), the C++ Standard library depends on components supplied by a C++ program. If these components do not meet their requirements, the Standard places no requirements on the implementation."

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

4

Error: User Rate Limit ExceededfunctionalError: User Rate Limit Exceededgreater<>, less<>Error: User Rate Limit Exceededmem_fun_tError: User Rate Limit Exceededunary_operator<>Error: User Rate Limit Exceededbinary_operator<>Error: User Rate Limit Exceeded

4

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

38

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

  • If it doesn't have any virtual methods, then you shouldn't be using it as a base. This rules out std::vector and the like.
  • If it does have virtual methods, then it is a candidate for usage as a base class.
  • If there are lots of friend statements floating around, then steer clear since there is probably an encapsulation problem.
  • If it is a template, then look closer before you inherit from it since you can probably customize it with specializations instead.
  • The presence of policy-based mechanism (e.g., std::char_traits) is a pretty good clue that you shouldn't be using it as a base.

Error: User Rate Limit Exceededblack and whiteError: User Rate Limit Exceeded

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceededwhat()Error: User Rate Limit Exceededstd::exceptionError: User Rate Limit Exceeded"best practice".

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceededstd::stackError: User Rate Limit Exceededstd::queueError: User Rate Limit ExceededprotectedError: User Rate Limit Exceeded
5

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit ExceededstreambufError: User Rate Limit Exceeded

std::exceptionError: User Rate Limit Exceeded

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceededexception::what()Error: User Rate Limit ExceededexceptionError: User Rate Limit ExceededexceptionError: User Rate Limit Exceededstd::exceptionError: User Rate Limit Exceeded

4

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceededoperator newError: User Rate Limit Exceededoperator deleteError: User Rate Limit Exceededoperator deleteError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Похожие вопросы