开发者

Pointer to vector of vectors of ints [closed]

开发者 https://www.devze.com 2023-04-07 05:18 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

Hi I am trying to create a pointer to a vector of vectors of int, that is to achieve an effe开发者_如何学编程ct similar to 2-d arrays. I use the following initialization -

vector< vector<int> >* v = new vector< <vector<int> >(10, vector<int>(5, 1));

However, gcc complains-

$ c++ test.cpp
test.cpp: In member function `int MonochromaticBoard::theMin(std::vector<std::string, std::allocator<std::string> >)':
test.cpp:14: error: template argument 1 is invalid
test.cpp:14: error: template argument 2 is invalid

However, this works -

vector< vector<int> > v(10, vector<int>(5, 1));

I tried searching on the web but couldn't find an answer[1], any idea whats wrong in the first syntax?

[1] I found that someone at http://www.dreamincode.net/forums/topic/170469-pointer-to-vector-of-vectors/ was successful in initializing like that, but not sure.


Looks like you just have a typo - one too many <'s after new vector:

int main()  
{
    vector< vector<int> >* v = new vector< vector<int> >(10, vector<int>(5, 1));
}
0

精彩评论

暂无评论...
验证码 换一张
取 消