C ++指向模板类类型的指针,需要使用括号 - 为什么?

时间:2013-09-04 22:34:58

标签: c++ parsing templates pointers

我有一个使用模板类型的类,我需要声明一个指向该类实例的指针。

以下是此类的一个示例:

template <std::size_t N>
class PlaneSection
{
    // Code here
}

我试图声明一个(const)指针,如下所示:

PlaneSection<4>* const plane_section_ptr = &plane_section;

其中plane_section是类PlaneSection的实例。

然而,这不会编译。 (错误g ++ - 4.8给了我error: missing template arguments before '*' token

然后我尝试了这个:

((PlaneSection<4>)* const) plane_section_ptr = &plane_section;

然后编译。

我的问题是为什么我需要额外的2对括号?为什么((PlaneSection<4>)* const)有效,但(PlaneSection<4>)* constPlaneSection<4>* const都不是?

修改

我再次重新编译,但这次我不得不将其更改为:

(((PlaneSection<4>)*) const)

0 个答案:

没有答案