【发布时间】:2016-12-05 21:45:49
【问题描述】:
我在code being adapted from here 中有一个虚拟方法类型int_type,这是代码给出编译错误的唯一情况:
‘int_type’ does not name a type
int_type ThreadLogStream::overflow(int_type v)
^.
到目前为止的调试步骤
-
1234563
根据this reference,int_type确实属于
basic_streambuf,但称它为Traits::int_type不起作用。我尝试对问题变量进行 typedef,如下面的 typedef 所示,但无法识别
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,则不应该编译。当函数在类之外声明时,您应该使用限定名称作为返回类型。
标签: c++ std typedef virtual-functions streambuf