继承的构造函数和stl容器错误
Inherited constructor and stl containers error
我在玩继承的构造函数,但我很难理解为什么当我试图从std::string继承时,gcc会抱怨。
我知道这不是最好的做法,应该不惜一切代价避免,所以在对我大喊大叫之前,我不会在任何地方实施它:-)这纯粹是出于好奇。
我还用一个简单的已定义类尝试了同样的场景,但我没有遇到同样的问题。
#include <string>
#include <vector>
#include <iostream>
using namespace std;
template <typename T>
struct Wrapper : public T
{
using T::T;
};
struct A{
A(int a) : _a(a) {}
int _a;
};
int main()
{
Wrapper<string> s("asd"); //compiles
string a = "aaa";
Wrapper<string> s2(a); //does not compile
Wrapper<A> a(1);
int temp = 1;
Wrapper<A> b(temp);
}
实际错误摘录:
main.cpp:25:24:错误:没有用于调用
'Wrapper<std::basic_string<char> >::Wrapper(std::string&)'
的匹配函数Wrapper<string> s2(a);
T
Wrapper(T const& t):
T(t){}
可能还有非const
和移动变体:
Wrapper(T& t):
T(t){}
Wrapper(T&& t):
T(std::move(t)){}
相关文章:
- 使用STL对用户输入数组进行排序的错误有什么解决方案吗?
- STL向量上出现奇怪的复制构造函数错误
- 为什么STL优先级队列错误地分配了我的类对象
- C++ MSVC 中的自定义 STL 分配器错误?
- 为什么包含任意 STL 标头可以解决这些编译错误?
- fstream.h 中的 STL 命名空间错误与 qmake/make.
- STL 对priority_queue<int、结构>错误
- 在Visual Studio 2013中编译的STL列表代码在Visual Studio 2019中给出了错误.想知道原
- 为什么这个正则表达式在 STL 世界中是错误的?
- STL unordered_map编译错误
- STL C 中不同类型的列表声明的错误
- 错误试图实现STL迭代器
- Visual Studio 中(基于字符的)STL(流)容器的编译错误
- xcode 上的 stl 链接错误
- 用反向_iterator stl错误解密upper_bound
- STL 中是否有任何错误代码异常
- 为什么当代码尝试在 STL 映射中查找键时出现分段错误
- 为什么这不是正确的生产者消费者模型以及当我使用 stl 队列时导致错误的原因
- STL 迭代器:断言错误
- 分割错误:STL MAP的异常行为