相关疑难解决方法(0)

尝试与typedef成为朋友时,"elaborated type指的是typedef"错误

假设我有以下代码(简单的CRTP类层次结构).我想键入基类类型来保存自己输入(在我的实际代码中,我多次使用基类类型,基类需要几个模板参数),我需要与基类成为朋友,因为我想保留私有的实施.

template< class D >
class Base
{

public:

    void foo() { *static_cast< D * >(this)->foo_i(); }

};

template< class T >
class Derived : public Base< Derived< T > >
{

public:

    typedef class Base< Derived< T > > BaseType;

private:

    // This here is the offending line 
    friend class BaseType;

    void foo_i() { std::cout << "foo\n"; }

};

Derived< int > crash_dummy;
Run Code Online (Sandbox Code Playgroud)

铿说:

[...]/main.cpp:38:22: error: elaborated type refers to a typedef
    friend class BaseType;
             ^
[...]/main.cpp:33:44: note: declared …
Run Code Online (Sandbox Code Playgroud)

c++ templates typedef

7
推荐指数
1
解决办法
4833
查看次数

标签 统计

c++ ×1

templates ×1

typedef ×1