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
我有以下输入
<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.