我有一个使用模板类型的类,我需要声明一个指向该类实例的指针。
以下是此类的一个示例:
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>)* const
或PlaneSection<4>* const
都不是?
修改
我再次重新编译,但这次我不得不将其更改为:
(((PlaneSection<4>)*) const)