相关疑难解决方法(0)

继承和覆盖std :: string的函数?

既然std::string实际上是typedef模板类,我怎么能覆盖呢?我想制作一个std::string能返回正确长度的UTF-8 .

c++ unicode utf-8 character-encoding

12
推荐指数
2
解决办法
5398
查看次数

将std :: vector重命名为另一个类进行重载?

看看这段代码.

#include <vector>

template<class ...Args>
using other_vector = std::vector<Args...>;

template<class T>
void f(std::vector<T>& ) {}
template<class T>
void f(other_vector<T>& ) {}

int main()
{
    other_vector<int> b;
    f(b);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

它没有编译,因为f正在重新声明.我完全理解错误.但是,我需要一个行为类似的第二个类std::vector<T>,但将被视为一个不同的类型,因此重载,如上例所示,是合法的.

我能做什么?

  • 让新类std::vector<T>作为基类.这可能有效,但不应该从std容器继承.
  • 让新类具有std :: vector类型的成员,然后重新声明所有函数以重定向到成员的函数.听起来很多工作.

有更好的选择吗?允许使用C++ 11或C++ 14.

c++ stdvector c++11

6
推荐指数
1
解决办法
474
查看次数

标签 统计

c++ ×2

c++11 ×1

character-encoding ×1

stdvector ×1

unicode ×1

utf-8 ×1