vector and const

后端 未结 10 1715
無奈伤痛
無奈伤痛 2020-12-03 07:13

Consider this

 void f(vector& p)
 {
 }
 int main()
 { 
  vector nonConstVec;
  f(nonConstVec);
 }

The followi

10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-03 07:32

    Both vector and vector are completely different types. Even if you write const T* inside your main(), your code wont compile. You need to provide specialization inside main.

    The following compiles:

     #include
     using namespace std;
    
     template
     void f(vector& p)
     {
     }
     int main()
     { 
         vector nonConstVec;
         f(nonConstVec);
     }
    

提交回复
热议问题