class Solution { static constexpr int check[10] = {0, 0, 1, -1, -1, 1, 1, -1, 0, 1}; public: int rotatedDigits(int n) { int ans = 0; for (int i = 1; i <= n; ++i) { std::string num = std::to_string(i); bool valid = true, diff = false; for (char ch: num) { if (check[ch - '0'] == -1) { valid = false; } else if (check[ch - '0'] == 1) { diff = true; } } if (valid && diff) { ++ans; } } return ans; } };
编译遇到undefined Solution::check问题,这是因为函数里的check[xx]用到了check的地址
而static声明的东西没有地址,需要外部声明给定一个地址
所以加上类外部声明,cxx17以后不用了,constexpr被隐式inline了
int constexpr Solution::check[];标签:undefined,int,Solution,constexpr,static,check From: https://www.cnblogs.com/yanzhao-x/p/16728184.html