找不到基的构造函数
Constructor from base not found
#include <string_view>
class str_ref : public std::string_view
{
public:
using std::string_view::string_view;
};
int main()
{
std::string_view sv;
str_ref sr("", 0);
str_ref sr2(sv); // error C2664: 'str_ref::str_ref(const str_ref &)': cannot convert argument 1 from 'std::string_view' to 'const char *const '
}
为什么在这里找不到 (string_view( 的构造函数?不应该使用 using 语句导入此构造函数吗?正在找到(常量字符*,size_t(构造函数。我正在使用VS2017。
不应该使用 using 语句导入此构造函数吗?
它是正确导入的,但您必须自己在派生类中定义该构造器。
编译器不会为派生类自动生成类似的构造函数:
#include <string_view>
class str_ref : public std::string_view
{
public:
using std::string_view::string_view;
str_ref(const std::string_view& sv) : std::string_view(sv) {} // <<<<
};
int main()
{
std::string_view sv;
str_ref sr("", 0);
str_ref sr2(sv);
}
观看现场演示
相关文章:
- 给定一个 3 x 3 矩阵或任何 n x n 矩阵,为什么我的以下函数找不到对角线差异?
- 类没有合适的复制构造函数,找不到二进制运算符 '=',
- 找不到基的构造函数
- 在哈希表复制构造函数中找不到错误
- GCC LD:构造I386找不到符号
- 找不到构造函数 - 如何将 CPP 文件添加到 Qt 构建过程
- 构造函数找不到合适的定义,以及 100 个其他错误?
- 找不到默认构造函数
- 找不到C++默认构造函数
- GCC (MingW-w64) 找不到基构造函数 (!?)
- G++ 在执行复制初始化时找不到正确的复制构造函数
- std::调用函数时找不到函数构造函数
- 模板类找不到构造函数
- 什么时候在构造函数的类定义中通过普通查找找不到 mem-initializer-id?
- 复制构造函数 c++:编译器在使用 a = b 时找不到它
- 类函数找不到类定义的变量
- 为什么在对象表达式的上下文中找不到我的构造函数
- 在HardwareStore类中找不到匹配的构造函数(c++)
- 如果模板类构造函数和成员函数的定义与使用分离,则G++链接器找不到它们
- 平均函数找不到正确的平均c++