本文介绍了MSVC C ++ 11:非标准构造继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Windows本地C ++库我已经过头,有时它构造方面没有提供具有相同的功能(5-10额外的构造函数)的实际方法。这使得基础延伸出的C ++类真的很难因为没有合适的构造继承(不重新声明他们和转接电话)

In my Windows Native C++ library I've sometimes overdone it in terms of constructors without providing actual methods with same functionality (5-10 extra constructors). This makes basic extending a C++ class really hard as there's no proper constructor inheritance (without redeclaring them and forwarding calls).

我用MSVC (是的,微笑所有你想要的!) 的问题是:有没有办法继承除了默认的构造函数/构造的复印构造函数使用使用因为,如果有人决定延长一类,我滥用构造(W / O增加新的特性,并与单继承),这是一场噩梦。

I use MSVC. (Yes, smile all you want!) Question is: Is there a way to inherit constructors except the default constructor/copy-constructor using using? Because, if someone decided to extend a class where I abuse constructors (w/o adding new properties and with single inheritance), it's a nightmare.

(例如code)

class parent {
public:
    parent(){
        std::cout << __FUNCTION__ << ':' << __LINE__ << std::endl;
    }
    // a non-standard constructor
    parent(const std::nullptr_t&):parent(){
        std::cout << __FUNCTION__ << ':' << __LINE__ << std::endl;
    }
};

// adds nothing to parent but helper methods
// and maybe self-reliant properties with their own constructors
// so no constructor is required to initialize child class properties
class child: public parent {
public:
     // using parent::parent; // of no real use
    child(){
        std::cout << __FUNCTION__ << ':' << __LINE__ << std::endl;
    }
    // need to forward call
    child(const std::nullptr_t&):parent(nullptr){
        std::cout << __FUNCTION__ << ':' << __LINE__ << std::endl;
    }
};

当我建立我的基CRTP类需要扩展它来建立我的默认类,然后让别人来扩展和建立自己的变体,同时维持链式法的功能这多重构造继承噩梦发生特别的(父儿童)的秩序。

This multiple-constructor inheritance nightmare occurs especially when I build a my base CRTP class and need to extend it to build my default class and then allow others to extend and build their own variants while maintaining chainable method functionality (parent to child) in order.

在MSVC不管怎么说,使用父::父不继承父(常量的std :: nullptr_t&放大器;)是否应该根据 C ++ 11 标准或不?我应该期待在 VC13 这将极大地影响我的选择风格为这个公共重写

In MSVC anyways, using parent::parent does not inherit the parent(const std::nullptr_t&). Is it supposed to according to the C++11 standard or not? Should I expect such functionality in VC13? This will greatly impact my choice in style for this public rewrite.

我也想知道为什么,对于 C ++ 11 ,他们并没有弄清楚,当我的一个单类,而不是增加新的属性,则应该继承父母的默认行为(构造函数,赋值运算符等)。这是很有道理......,编译器会看着办吧。

I also wonder why, for C++11, they did not figure out that when I'm extending a single class and not adding new properties, it should inherit the parent's default behavior (constructors, assignment operators, etc.). It just makes sense... and the compiler could figure it out.

推荐答案

据的,继承构造函数不来VC ++在不久的将来:

According to the VS2013 Roadmap from Herb Sutter's talk at //build, inheriting constructors are not coming to VC++ in the near future:

他们是有计划的。

这篇关于MSVC C ++ 11:非标准构造继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 19:32