为类MyString设置reverse_iterator :: rbegin()和reverse_iterator :: rend()

时间:2018-12-04 14:57:22

标签: c++

class MyString
{
    private:
        char *m_string;
        int m_size;
        int m_reserved_size;
    public:
        typedef char * reverse_iterator;
        typedef const char * const_reverse_iterator;

    reverse_iterator rbegin();
    {
        return reverse_iterator(end());
    }
    const_reverse_iterator rbegin() const;

    reverse_iterator rend();
    {
        return reverse_iterator(begin());
    }
    const_reverse_iterator rend() const;

    int main()
    {
        MyString str("this is a test string");
        MyString::reverse_iterator rit;
        for (rit = str.rbegin(); rit != str.rend(); rit++)cout << *rit;   
    }

预期结果:“ gnirts tsi si siht”,但是我有一个错误。请帮助我做正确的事。我应该定义reverse_iterator以及如何执行。

0 个答案:

没有答案