Difference between decltype and typeof?

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

Two question regarding decltype and typeof:

  • Is there any difference between the decltype and typeof operato
5条回答
  •  猫巷女王i
    2021-01-01 11:20

    Well, typeof is a non-standard GNU C extension that you can use in GNU C++ because GCC allows you to use features from other languages in another (not always though), so they really shouldn't be compared.

    Of course other non-standard extensions may exist for other compilers, but GCC is definitely the most widely documented implementation.

    To answer the question: it can't be obsolete if it was never a feature.

    If you want to compare the merits of either method in C++ then there is semantically no difference unless you're dealing with references. You should use decltype because it is portable and standards conforming.

提交回复
热议问题