How to disallow temporaries

后端 未结 10 1712
一个人的身影
一个人的身影 2020-12-02 05:19

For a class Foo, is there a way to disallow constructing it without giving it a name?

For example:

Foo(\"hi\");

And only allow it i

10条回答
  •  借酒劲吻你
    2020-12-02 06:06

    No, I'm afraid this isn't possible. But you could get the same effect by creating a macro.

    #define FOO(x) Foo _foo(x)
    

    With this in place, you can just write FOO(x) instead of Foo my_foo(x).

提交回复
热议问题