noexcept depending on method of member

梦想的初衷 提交于 2019-12-23 18:53:37

问题


Related to this question, I want to specify my private section after my public interface.

template<class T, void (T::*f)()>
class B
{
public:
    void g(int y) noexcept(noexcept(x.*f()))
    {}
private:
    T& x;
};

But I get an error from Clang that x is an undeclared identifyer.

mm_test.cpp:14:34: error: use of undeclared identifier 'x'
    void g(int y) noexcept(noexcept(x.*f()))
                                    ^

It compiles just fine if the declaration of member x occurs before the declaration of g. Am I not supposed to be able to use a member variable in a noexcept operator earlier in the class definition than its declaration? If not, how could I achieve an equivalent noexcept specifier without moving the declaration of x ahead?

来源:https://stackoverflow.com/questions/27241938/noexcept-depending-on-method-of-member

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!