int_type不是命名类型的挫败感
int_type not naming type frustration
我有一个虚拟方法类型的代码中的int_type
是从这里改编的,这是代码给出编译错误的唯一情况:
‘int_type’ does not name a type
int_type ThreadLogStream::overflow(int_type v)
^.
到目前为止的调试步骤
如果我徘徊在QT创建者IDE中的
int_type
的任何其他实例上,它显示了traits_type::int_type std::basic_streambuf::int_type
,这意味着int_type
的所有其他实例都不应引起问题。根据此参考,INT_TYPE确实属于
basic_streambuf
,但称其为Traits::int_type
不起作用。我试图输入问题变量,如下所示,但
char_type
和traits_type
尚未识别。
threadlogstream.cpp
...
int_type ThreadLogStream::overflow(int_type a)
{
int_type b = a; //This gives no errors
return b;
}
...
threadlogstream.hpp
#include <iostream>
#include <streambuf>
#include <string>
//typedef std::basic_streambuf< char_type, traits_type> base_class;
//typedef typename base_class::int_type int_type;
class ThreadLogStream : public QObject, std::basic_streambuf<char> {
Q_OBJECT
public:
ThreadLogStream(std::ostream &stream);
~ThreadLogStream();
protected:
virtual int_type overflow(int_type v); // This gives no errors
virtual std::streamsize xsputn(const char *p, std::streamsize n);
}
请帮忙 - 我在这方面丢了头发。
看来您的int_type
应该代表std::basic_streambuf<>::int_type
。在这种情况下
ThreadLogStream::int_type ThreadLogStream::overflow(int_type a)
{
...
即。为功能返回类型使用合格的名称。参数名称在类范围中查找(这就是为什么int_type
在参数列表中填充罚款的原因)。但是返回类型在封闭范围中查找,这就是为什么您必须明确质量质量。
这就是它一直在C 中的方式。
但是,在thailting返回类型语法中的返回类型(自C 11以来可用)也在类范围中查找,这意味着您可以替代地执行此操作
auto ThreadLogStream::overflow(int_type a) -> int_type
{
...
看起来您需要使其成为尾随的返回类型,例如:
auto ThreadLogStream::overflow(int_type v) -> int_type {
// ...
}
说明:int_type
需要在ThreadLogStream
的范围中查找,但是如果您有领先的返回类型,它将在命名空间范围中查找,因为它在之前您提到了名称ThreadLogStream::overflow
,这会触发查找ThreadLogStream
的范围。通过在合格的ID 之后放置返回类型,避免了此问题。
- 在类型和包装器之间reinterpret_cast是否安全<Type>?
- std::unordered_map 类型对象声明期间出现"field has incomplete type"错误
- 在"结构提升::enable_if<提升::is_pod<T>,无效>"中没有名为"type"的类型
- C++ "错误:在'类 std::result_of< ... >"中没有名为'type'的类型"
- Cython:如何从C级类型获取'actual Python type'(类型代码/dtype)
- 作为模板类型参数,为什么 type[N] 与其专用版本不匹配----模板<类 T>类 S<T[]>
- Clang 对使用的类型别名发出"unused type alias"警告
- 检测<T>某些非数字类型 T 的 std::numeric::type 的特化
- 不同指针类型之间的无效比较:'type*' 和 'type&(*)()'
- 按参数类型更改"return type template"
- 在shared_from_this()中的错误类型(在继承类中)(是否有dyn.type-ware shared Poi
- grpc & protobuf -- 错误:std::result_of<> 中没有名为 'type' 的类型
- 类 std::result 中没有名为 "type" 的类型
- 访问基类型数组成员(Int-to-type习惯用法)
- 类类型的"Incomplete type isn't allowed"数组
- `type'和`const type'的类型特征
- 我是否可以保证SizeOf(type)== sizeof(无符号类型)
- 编译错误C++与上面定义的发生错误的类型"does not name a type"?
- 仅当我提供类型检查规则时才"No type checking rule"错误
- 使用公共类函数初始化节点类型<Type>指针C++