Using type declared in template base class

Hi

I have the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
template <typename T>
class B
{
    public:
        using ID = size_t;
    protected:
        int x;
};

template <typename T>
class C : public B <T>
{
    public:
        
        ID id; // error - does not name a type 
        typename B<T>::ID id; // works but very ugly
        void setX()
        {
            this->x = 5; 
        }
    private:
};


When I wish to use the type ID (declared in class B) in class C then I need to use typename B<T>::ID - this is very ugly and cumbersome so I wondered whether there is a less ugly way of doing it. Is it normal just to have a using statement:

1
2
using ID = typename B<T>::ID;
ID id;
Yes.

This would suffice:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
template <typename T>
class B
{
    public:
        using ID = std::size_t;
};

template <typename T>
class C : public B <T>
{
    using typename B<T>::ID ;
    
    ID id = 1 ; // fine
};
Topic archived. No new replies allowed.