나는 다음 streambuf
에서 파생되는 지층을 쓰고 있습니다 std::basic_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());
...
오류 :
error: 'int_type' does not name a type
virtual int_type
^~~~~~~~
note: (perhaps 'typename std::basic_streambuf<_CharT, _Traits>::int_type' was intended)
ㅋ. 컴파일러는 내가 원하는 것을 알고 있지만하지 않습니다. 왜?
다음은 부모 std 클래스의 첫 번째 줄입니다.
template<typename _CharT, typename _Traits>
class basic_streambuf
{
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;
...
파생 클래스에서 거의 모든 사용 된 유형을 다시 한 번 다시 선언합니다.
class Derived : class Parent {
using Parent::int_type; // for non-templated
using typename Parent::char_type;
...
더 나은 방법을 알고 있습니까? C ++ 11,14는 환영합니다.
클래스 템플릿에서 유형을 상속하는 유일한 방법은 유형을 다시 정의하는 것입니다. 제 경우 가장 간단한 방법은 Parent 클래스에서 복사하여 붙여 넣는 것입니다.
/// 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;
...
이 방법은 C++98
호환됩니다.
다른 현대적이고 좋은 방법은 내부 유형 을 선언 SuperType
하고 다시 사용 using
하는 것입니다.
/// 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;
...
의 내부 형식은 SuperBuffer
( SuperBuffer::InnerX
)하지 않고 직접 사용할 수 =
있지만, SuperBuffer::InnerX::InnerY
재사용해야 =
하기 때문에 InnerX
의 기본 형식이 아닙니다 BasicSocketBuffer
.
typename
클래스 템플릿에 필요합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다