gpt4 book ai didi

c++ - 数组元素作为非类型模板参数

转载 作者:行者123 更新时间:2023-11-28 07:30:51 25 4
gpt4 key购买 nike

是否有可能克服这个问题:

                class Constants
{
static Std_ReturnType dtcSitzheizungSchalteMittelkonsoleHlTasterHaengt( UInt8 const value )
{
return Rte_Call_demSitzheizungSchalteMittelkonsoleHlTasterHaengt_SetEventStatus( value );
}

static DTCSetter * const DTCSETTER_WITH_NO_DID[SEAT_HEATING_DTCS_COUNT]; //how to use an element of this array as a non type template parameter ?
};

template class ButtonStuckPolicy< &Constants::dtcSitzheizungSchalteMittelkonsoleHlTasterHaengt >; //works

在 C++ 03 中?

一般来说,是否可以将静态数组元素作为非类型模板参数传递?

谢谢

最佳答案

任何具有外部链接的对象的地址在 C++03 中都是公平的游戏。但是 value 不是,除非它是 const 并用整数常量表达式初始化。正如您所拥有的,子对象在 C++11 之前不需要应用。

您所拥有的是将地址参数传递给 int 参数,这在任何上下文中都不起作用。

这在 C++11 中是可以的:

const int x[100] = {}; // zero-initialize
template<int T>
class foo;
foo<x[0]> y;

这是这样的:

int x[100];
template<int *T>
class foo;
foo<&x[0]> y;

这在 C++03 中也是可以的,因为它使用整个命名对象的地址:

int x[100];
template<int *T>
class foo;
foo<x> y;

关于c++ - 数组元素作为非类型模板参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17759658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com