2017-06-13 70 views
-1

代碼中出現了什麼問題? 我有:在函數調用中定義了一個命名變量

"error: expected primary-expression before 'j'"

#include <vector> 
using namespace std; 

void foo(vector<int>& v){ 
} 

int main() 
{ 
    foo(vector<int> j); 
    return 0; 
} 
+0

@StoryTeller這樣的評論是b est附有一個鏈接到SO [良好的C++書籍列表](https://stackoverflow.com/q/388242/1782465)。 – Angew

回答

1

這是無效的:

foo(vector<int> j); 

,因爲你不能定義一個函數調用一個命名的變量....

你的意思肯定

int main() 
{ 
    vector<int> j; 
    foo(j); 
    return 0; 
} 
相關問題