Difference between decltype and typeof?

前端 未结 5 652
别跟我提以往
别跟我提以往 2021-01-01 10:48

Two question regarding decltype and typeof:

  • Is there any difference between the decltype and typeof operato
5条回答
  •  温柔的废话
    2021-01-01 11:21

    There is no typeof operator in c++. While it is true that such a functionality has been offered by most compilers for quite some time, it has always been a compiler specific language extension. Therefore comparing the behaviour of the two in general doesn't make sense, since the behaviour of typeof (if it even exists) is extremely platform dependent.

    Since we now have a standard way of getting the type of a variable/expression, there is really no reason to rely on non portable extensions, so I would say it's pretty much obsolete.

    Another thing to consider is that if the behaviour is of typeof isn't compatible with decltype for a given compiler it is possible that the typeof extension won't get much development to encompass new language features in the future (meaning it might simply not work with e.g. lambdas). I don't know whether or not that is currently the case, but it is a distinct possibility.

提交回复
热议问题