新的 C++ 标准下不能编译的代码

新的 C++ 标准下不能编译的代码

新的 C++ 标准下不能编译的代码

#pragma once

class CUIAutomationChangesEventHandler 
{
public:
  CUIAutomationChangesEventHandler() = default;
  virtual ~CUIAutomationChangesEventHandler() = default;


  template<typename Function> static int ForEachChangeIdentifiers(Function func);

  static size_t GetChangeIdCount();
  static int GetAllChangeId(int *id, size_t size);

private:
  static const int element_changes_id_[];
  long int ref_count_{ 1L };

};

template<typename Function>
inline int CUIAutomationChangesEventHandler::ForEachChangeIdentifiers(Function func)
{
  for (size_t i = 0LU; i < sizeof(element_changes_id_) / sizeof(element_changes_id_[0]); ++i)
    if (element_changes_id_[i] != 0)
      func(element_changes_id_[i]);
  return 0;
}
#include "size.h"

const int CUIAutomationChangesEventHandler::element_changes_id_[] =
{
  1,
  2,
  3
};

上面的代码,用 vc++ 2022 编译时,使用 /std:c++11/std:c++14/std:c++17 ,可以编译通过,使用 /std:c++20/std:c++latest ,不能编译通过。提示:

error C2070: “const int []”: 非法的 sizeof 操作数
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dowhileprogramming

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值