I am currently working on a leetcode question, and try to track down the code process in my end, this is my solution:
#include <iostream>
#include <vector>
#include <stack>
#include <utility>
using namespace std;
vector<int> direction{-1, 0, 1, 0, -1};
int maxAreaOfIsland(vector<vector<int>>&grid){
int m = grid.size(), n = m ? grid[0].size() : 0, local_area, area = 0, x, y;
for (int i = 0; i < m; ++i){
for (int j = 0; j < n; ++j){
if(grid[i][j]){
local_area = 1;
grid[i][j] = 0;
stack<pair<int, int>> island;
island.push({i, j});
while(!island.empty()){
auto [r, c] = island.top(); \\problem line, vscode can't understand it
island.pop();
for (int k = 0; k < 4; ++k){
x = r + direction[k], y = c + direction[k + 1];
if(x>=0 && x<m && y>=0 && y<n && grid[x][y]==1){
grid[x][y] = 0;
++local_area;
island.push({x, y});
}
}
}
area = max(area, local_area);
}
}
}
return area;
}
this code works on the leetcode side, but not mine, here is the warning
[Running] cd "c:\Users\chen1\OneDrive\Desktop\C_C++tut\" && g++ leetcode695.cpp -o leetcode695 && "c:\Users\chen1\OneDrive\Desktop\C_C++tut\"leetcode695
leetcode695.cpp: In function 'int maxAreaOfIsland(std::vector<std::vector<int> >&)':
leetcode695.cpp:23:16: warning: structured bindings only available with -std=c++17 or -std=gnu++17
auto [r, c] = island.top();
^
C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e): undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
[Done] exited with code=1 in 0.932 seconds
Can someone explains why, although I get an alternative way to replace it, it is still annoying and perplexing
thanks for helping
additionally!!!
I actually have my main function; the problem here is a syntax error where leetcode's compiler recognizes it, but not g++, the line that causes the problem is auto [r, c] = island.top();
, if I alter it to
int r = get<0>(island.top());
int c = get<1>(island.top());
then it works fine, I just don't understand why leetcode compiler can understand it, but not g++