テンプレート型を使用するクラスがあり、そのクラスのインスタンスへのポインターを宣言する必要がありました。
このようなクラスの例を次に示します。
template <std::size_t N>
class PlaneSection
{
// Code here
}
次のように、(const) ポインターを宣言しようとしました。
PlaneSection<4>* const plane_section_ptr = &plane_section;
はclassplane_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)