no match for 'operator=' in vector[][]

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • orangemonkey
    New Member
    • Apr 2007
    • 16

    #1

    no match for 'operator=' in vector[][]

    Code:
    #include <iostream>
    #include <math.h>
    #include <vector>
    using namespace std;
    
    int main (void) {
    
    int sv = 0, fv = 0;
    
    cout << "Start Value:" << endl;
    cin >> sv;
    cout << "End Value:" << endl;
    cin >> fv;
    cout << endl;
    
    int size = (int)sqrt(fv-sv)+5;
    
    [B]vector <vector<int> > grid [size][size];
    vector <vector<int> > grid2 [15][15];[/B]
    
    int midx = (int)(sqrt(fv-sv)+5/2)-1, midy = (int)(sqrt(fv-sv)+5/2)-1;
    int down = 0, right = 0, left = 0, up = 0;
    int yy = 0, xx = 0;
    int count = 0;
    string dir = "down";
    
    for (int i = 0; i <= 5 ; i++) {
    
    if (dir=="down") {
    for (int i2 = 0; i2 < 1 ; i2++) {
    [B]grid2[1][1] = 5;
    grid[0][0] = 5;
    grid [midx][midy] = i;[/B]
    }
    dir = "right";
    }
    
    }
    
    
    
    
    
    
    }
    When I compile the code above, I get this error "no match for 'operator=' in 'grid2[1][1] = 5' ". I'm clueless as to what's the problem... Thx!


    31 C:\Documents and Settings\Admini strator\Desktop \Testing Files Folder\J42001.c pp no match for 'operator=' in 'grid2[1][1] = 5'

    note C:\Dev-Cpp\include\c++ \3.4.2\bits\vec tor.tcc:131 candidates are: std::vector<_Tp , _Alloc>& std::vector<_Tp , _Alloc>::operat or=(const std::vector<_Tp , _Alloc>&) [with _Tp = std::vector<int , std::allocator< int> >, _Alloc = std::allocator< std::vector<int , std::allocator< int> > >]

    32 C:\Documents and Settings\Admini strator\Desktop \Testing Files Folder\J42001.c pp no match for 'operator=' in 'grid[0][0] = 5'
  • orangemonkey
    New Member
    • Apr 2007
    • 16

    #2
    nvm.. i know what's the problem ...
    i have to declare it like this vector <vector<int> > grid2(15, vector<int>(15) );

    Comment

    Working...