Is it possible to have an “auto” member variable?

后端 未结 4 1660
别跟我提以往
别跟我提以往 2021-01-03 20:54

For example I wanted to have a variable of type auto because I\'m not sure what type it will be.

When I try to declare it in class/struct declaration it

4条回答
  •  悲&欢浪女
    2021-01-03 21:25

    No. Each constructor could have its own initializer for start, so there could be no consistent type to use.

    If you do have a usable expression, you can use that:

    struct Timer {
    
       Foo getAFoo();
    
       delctype(Timer().getAFoo().Bar()) start;
    
       Timer() : start(getAFoo().Bar()) { /***/ }
    };
    

提交回复
热议问题