2010-10-13 84 views
1

我有这些错误,我不能固定它:未知类型的C++

template< class char_type, class traits_type> 
class invalid_streambuf : public std::basic_streambuf< char_type, traits_type> 
{ 
typedef std::basic_streambuf< char_type, traits_type> base_class; 
using typename base_class::int_type; 
... 
virtual int_type overflow(int_type nChar) 
{ return 0; } 
... 
} 

'INT_TYPE' 没有指定类型

template< class char_type, class traits_type> 
class basic_thread_safe_log 
: protected basic_message_handler_log< char_type, traits_type> 
{ 
typedef basic_message_handler_log< char_type, traits_type> base_class; 
using typename base_class::string_type; 

void on_last_message(const string_type & str) 
{ 
    assert (str.empty()); 
} 
... 
} 

ISO C++禁止 'STRING_TYPE' 的声明无类型

+0

你使用什么编译器?编写它的人是否用任何东西编译它?如果是这样,什么? – 2010-10-13 16:15:41

+0

我现在修复它的问题是使用typedef,而不是使用 – Yassine 2010-10-13 16:31:32

回答

1

您似乎尝试使用应该在类的生成中知道的类型,但它们不是模板类的参数,因此它们不存在。

在这里,您可以简单地通过使用typedef而不是使用来解决问题。

+0

我试过typedef std :: basic_streambuf :: int_type int_typ;但在'int_typ'之前导致新错误';'' – Yassine 2010-10-13 16:21:06

+0

你有一个错字,它是int_type和e。如果它仍然不起作用,那么你的问题就在此之前。 – Klaim 2010-10-13 16:22:14

+0

你的tipp很好确定它现在正在工作,如下所示:typedef std :: basic_streambuf base_class; typedef typename base_class :: int_type int_type; – Yassine 2010-10-13 16:27:54

0

是你的代码还是其他人的代码?编译器告诉你int_type和string_type不是已知类型 - 在那个代码中没有这些类型的声明或定义,所以编译器说的是非常有意义的。

请注意,char_type和traits_type不是标准C++类型,因为您可能认为它们是(因此尝试使用类似名称的int_type和string_type)。它们是这里讨论的模板的类型参数。换言之,代码template< class char_type, class traits_type>的位包含模板代码的其余部分正在使用的类型名称的声明。

但是,如果您提出一个关于您想要在更高级别上实现的(单独)问题,可能会有所帮助。

+0

它不是我的代码问题不是与char_type和traits_type,而是与int_type,这是定义像这样typedef std :: basic_streambuf base_class; 使用typename base_class :: int_type; – Yassine 2010-10-13 16:13:09