调用基类构造函数而不命名其类 [英] call base class constructor without naming its class

查看:72
本文介绍了调用基类构造函数而不命名其类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class MyDerived: public Incredble<Difficult< And<Complicated, Long>>, And<Even, Longer>, BaseClass, Name>
{
public:
  MyDerived();
}


MyDerived::MyDerived
: ???(params)
{}

有什么方法可以调用基本构造函数而不写其全名,也可以不键入typeeffing吗?

Is there any way to call a base constructor without writing its full name and without typedeffing it?

原因显然是避免代码重复,并且如果基类模板参数中的详细信息发生更改,则会引入多个位置进行更改。

The reason is clearly to avoid code duplication and introducing multiple positions to change if a detail in the base class template params changes.

其中的第2级:

template <uint32 C>
class MyDerived: public Incredble<Difficult< And<Complicated, Long>>, And<Even, Longer>, BaseClass, Name>
{
public:
  MyDerived();
}

template <uint32 C>
MyDerived::MyDerived<C> 
: ???(C)
{
}


推荐答案

您可以使用 注入的类名 Incredible< ...> :: Incredible 引用自身,并且由于 MyDerived 不是类模板,不合格的查找将在其基类的范围内进行:

You could use injected-class-name. Incredible<...>::Incredible refers to itself, and since MyDerived isn't a class template, unqualified lookup will look in the scope of its base classes:

MyDerived::MyDerived
: Incredble(params)
{}

如果 Incredible 是一个相关名称,那么您需要对其进行限定。实际上,您可以简单地使用派生的类型名称来限定基类的 injected-class-name (h / t Johannes Schaub-litb ):

If Incredible is a dependent name, then you need to qualify it. You can actually simply use the derived type name to qualify the base class's injected-class-name (h/t Johannes Schaub-litb):

MyDerived::MyDerived
: MyDerived::Incredible(params)
{}

这在所有情况下均有效。

This will work in all cases.

这篇关于调用基类构造函数而不命名其类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆