C++ 错误:';int#U类型';不命名类型-如何继承typedefs和usings
我正在写stratumC++ 错误:';int#U类型';不命名类型-如何继承typedefs和usings,c++,c++11,c++14,C++,C++11,C++14,我正在写stratumstreambuf源于std::basic\u streambuf: /// Basic Socket Buffer template< typename CharT_, typename Traits_ = std::char_traits< CharT_ > > class BasicSocketBuffer //BasicSocketStreamBuffer : public std::basic
streambuf
源于std::basic\u streambuf
:
/// Basic Socket Buffer
template<
typename CharT_,
typename Traits_ = std::char_traits< CharT_ > >
class BasicSocketBuffer //BasicSocketStreamBuffer
: public std::basic_streambuf< CharT_, Traits_ >
{
...
virtual int_type
overflow(int_type __c = traits_type::eof());
...
你知道更好的方法吗?欢迎使用C++11,14
哈哈。编译器知道我想要什么,但不会做。为什么?
<> > C++标准称,必须使用<代码>类型名>代码>有效,因为类模板中的名称查找不依赖于依赖关系。
请参阅及其链接的说明
你知道更好的方法吗
这是正确的方法
哈哈。编译器知道我想要什么,但不会做。为什么?
<> > C++标准称,必须使用<代码>类型名>代码>有效,因为类模板中的名称查找不依赖于依赖关系。
请参阅及其链接的说明
你知道更好的方法吗
这是正确的方法。从类模板继承类型的唯一方法是重新定义它们。在我的例子中,最简单的方法是从父类复制粘贴:
/// Basic Socket Buffer
template<
typename CharT_,
typename Traits_ = std::char_traits< CharT_ > >
class BasicSocketBuffer //BasicSocketStreamBuffer
: public std::basic_streambuf< CharT_, Traits_ >
{
...
public:
//@{
/**
* These are standard types. They permit a standardized way of
* referring to names of (or names dependent on) the template
* parameters, which are specific to the implementation.
*/
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
...
SuperBuffer
(SuperBuffer::InnerX
)的内部类型可以在不使用=
的情况下直接使用,但是SuperBuffer::InnerX::InnerY
必须与=/code>一起重用,因为InnerX
不是BasicSocketBuffer
的基本类型
类模板需要typename
。从类模板继承类型的唯一方法是重新定义它们。在我的例子中,最简单的方法是从父类复制粘贴:
/// Basic Socket Buffer
template<
typename CharT_,
typename Traits_ = std::char_traits< CharT_ > >
class BasicSocketBuffer //BasicSocketStreamBuffer
: public std::basic_streambuf< CharT_, Traits_ >
{
...
public:
//@{
/**
* These are standard types. They permit a standardized way of
* referring to names of (or names dependent on) the template
* parameters, which are specific to the implementation.
*/
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
...
SuperBuffer
(SuperBuffer::InnerX
)的内部类型可以在不使用=
的情况下直接使用,但是SuperBuffer::InnerX::InnerY
必须与=/code>一起重用,因为InnerX
不是BasicSocketBuffer
的基本类型
类模板需要typename
。链接的问题是关于必须编写this->name
vsname
,但所有相同的内容都适用于访问typedefs。但问题不同:即使相同的内容适用,解决方案也不是this->int\u type
,但是typename base::int\u type
。好吧,几乎是一样的东西,但是你不能写this->int\u type
。@Barry我建议你找一个比这更好的复制品。@Barry投票支持repopen。请编辑被骗问题以合并“查找基类成员”(可能提到typedef)。或者选择另一个被骗的问题。重复关闭的原因有两个:一是防止SO数据库混乱,二是帮助用户找到(更)有价值的问题解决方案。因此,一个被愚弄的问题需要在搜索引擎上找到。链接的问题是关于必须写这个->名字
和名字
,但是所有相同的东西都适用于访问typedefs。但这是一个不同的问题:即使相同的东西适用,解决方案也不是这个->int\u类型
,但是typename base::int\u type
。好吧,几乎是一样的东西,但是你不能写this->int\u type
。@Barry我建议你找一个比这更好的复制品。@Barry投票支持repopen。请编辑被骗问题以合并“查找基类成员”(可能提到typedef)。或者选择另一个被骗的问题。重复关闭的原因有两个:一是防止SO数据库混乱,二是帮助用户找到(更)有价值的问题解决方案。因此,一个被欺骗的问题需要在搜索引擎上找到。
class Derived : class Parent {
using Parent::int_type; // for non-templated
using typename Parent::char_type;
...
/// Basic Socket Buffer
template<
typename CharT_,
typename Traits_ = std::char_traits< CharT_ > >
class BasicSocketBuffer //BasicSocketStreamBuffer
: public std::basic_streambuf< CharT_, Traits_ >
{
...
public:
//@{
/**
* These are standard types. They permit a standardized way of
* referring to names of (or names dependent on) the template
* parameters, which are specific to the implementation.
*/
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
...
/// Basic Socket Buffer
template<
typename CharT_,
typename Traits_ = std::char_traits< CharT_ > >
class BasicSocketBuffer //BasicSocketStreamBuffer
: public std::basic_streambuf< CharT_, Traits_ >
{
...
public:
using SuperBuffer = std::basic_streambuf< CharT_, Traits_ >;
//@{
/**
* These are standard types. They permit a standardized way of
* referring to names of (or names dependent on) the template
* parameters, which are specific to the implementation.
*/
using typename SuperBuffer::char_type;
using typename SuperBuffer::traits_type;
using typename SuperBuffer::int_type;
using typename SuperBuffer::pos_type;
using typename SuperBuffer::off_type;
...