I'm not sure what I should search for, so I'm sorry if this question have already been asked.
I have the following code
namespace ns {
template<typename crtp> struct base_type {
template<typename ...Args> base_type(Args &&...args);
};
}
struct derived_type: ns::base_type<derived_type> {
derived_type(int a, float b): base_type{a, b} {}
};
template<typename template_arg>
struct derived_template_type: ns::base_type<derived_template_type<template_arg>> {
derived_template_type(int a, float b): base_type{a, b} {}
};
derived_type
compiles fine. derived_template_type
fails to compile with following error (clang, c++17):
error: member initializer 'base_type' does not name a non-static data member or base class
derived_template_type(int a, float b): base_type{a, b} {}
^~~~~~~~~~~~~~~
To make it work, I have to replace this usage of base_type
with it's fully-qualified name ns::base_type<derived_template_type<template_arg>>
- so basically repeat what is already there on the base classes' list.
First question is: why is it so? The compiler should be aware that this is the base class, know where it's located and what are its template parameters - like in case of derived_type
- but apparently, it's not. Which language rule causes it to behave this way?
Second question is (obviously): can I do something to avoid this repeating?