小编Bee*_*eed的帖子

在switch条件中从类隐式转换为枚举类型

g ++ 4.9.0接受以下代码:

enum E { foo };

struct C {
  operator E() const { return foo; }
  operator E() { return foo; }
};

int main() {
  C c;
  switch (c) {
    case foo: break;
  }
}
Run Code Online (Sandbox Code Playgroud)

但是clang 3.4.1通过以下诊断拒绝它:

12 : error: multiple conversions from switch condition type 'C' to an integral or enumeration type
switch (c)
^ ~
5 : note: conversion to enumeration type 'E'
operator E() const { return foo; }
^
6 : note: conversion …
Run Code Online (Sandbox Code Playgroud)

c++ switch-statement language-lawyer implicit-conversion c++11

19
推荐指数
2
解决办法
1390
查看次数

数字大于0的Angular JS指令

我有以下输入 <input type="text" name="area" class="form-control" ng-pattern="onlyNumbers" ng-model="myForm.area" required>,ng-pattern只允许输入有数字.

$scope.onlyNumbers = /^\d+$/;
Run Code Online (Sandbox Code Playgroud)

我还想要一些方法告诉输入数字必须大于0.意味着用户不能输入像023这样的东西,它必须是23.

javascript regex jquery html5 angularjs

2
推荐指数
1
解决办法
6124
查看次数