亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

非命名空間范圍中的顯式特化

非命名空間范圍中的顯式特化

C++
largeQ 2019-08-31 16:37:44
template<typename T>class CConstraint{public:    CConstraint()    {    }    virtual ~CConstraint()    {    }    template <typename TL>    void Verify(int position, int constraints[])    {           }    template <>    void Verify<int>(int, int[])    {       }};在g ++下編譯它會產生以下錯誤:非命名空間范圍'class CConstraint'中的顯式特化在VC中,它編譯得很好。任何人都可以讓我知道解決方法嗎?
查看完整描述

3 回答

?
慕碼人8056858

TA貢獻1803條經驗 獲得超6個贊

解決它的另一種方法是委托私有函數并重載該函數。這樣,您仍然可以訪問*this外部模板參數類型的成員數據。


template<typename T>

struct identity { typedef T type; };


template<typename T>

class CConstraint

{

public:


  template <typename TL>

  void Verify(int position, int constraints[])

  {

    Verify(position, constraints, identity<TL>());

  }


private:

  template<typename TL>

  void Verify(int, int[], identity<TL>)

  {


  }


  void Verify(int, int[], identity<int>)

  {


  }

};


查看完整回答
反對 回復 2019-08-31
  • 3 回答
  • 0 關注
  • 682 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號