Can you make custom operators in C++?

前端 未结 6 1928
盖世英雄少女心
盖世英雄少女心 2020-12-01 00:24

Is it possible to make a custom operator so you can do things like this?

if (\"Hello, world!\" contains \"Hello\") ...

Note: this is a sepa

6条回答
  •  既然无缘
    2020-12-01 00:44

    Your suggestion would be nothing more than syntactic sugar for:

    if( contains( "Hello, world!", "Hello" ) ...
    

    and in fact there are already a functions to do that in both cstring and std::string. Which is perhaps a bit like answering "is it a good idea?" but not quite; rather asking "why would you need/want to?"

提交回复
热议问题