c++ - 为什么 ostream 不能转换为 ostream?

标签 c++ c++11 gcc

我正在对我的项目进行一些类型检查。下面的例子

using namespace std;

cout << ( is_convertible<ostream,ostream>::value ? "TRUE":"FALSE" ) << endl;

返回“假”。

谁能解释一下为什么?

最佳答案

is_convertible测试是否为虚函数

 To test() { return std::declval<From>(); }

格式正确(source)。

std::ostreamstd::basic_ostream<char> 的别名.它的复制构造函数被删除,它的移动构造函数被保护。

所以 test虚函数不是良构的。

简而言之,您询问是否可以从 ostream 移动构建 ostream,答案是“否”。

关于c++ - 为什么 ostream 不能转换为 ostream?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43070539/

相关文章:

c++ - 如何调整 2D C++ vector 的大小?

c++ - std::shared_ptr - 我可以使用等号 (=) 进行初始化吗?

c++ - 对另一个类中的一个类使用重载运算符

c++ - 如何遍历 boost::variant<std::vector<int>, std::vector<String>>?

c++ - 使用 double 的程序的意外行为

python - 在 macOS 上使用 OpenMP 与 Cython 进行编译

linux - 在 Ubuntu 上使用 IUP 和 C

c++ - 为什么虚拟表中有两个虚拟析构函数,非虚拟函数的地址在哪里(gcc4.6.3)

python - 如何修复错误 : command 'x86_64-linux-gnu-gcc' failed with exit status 1

c++ - 什么时候需要删除 C 风格的数组?