我希望我自己的类可以像vector一样进行列表初始化:
myClass a = {1, 2, 3};
Run Code Online (Sandbox Code Playgroud)
我怎么能用C++ 11功能呢?
我从我的设计中提取了这些样本类型:
type SomeType = T1 of int | T2 of string
type Condition = Int | String
Run Code Online (Sandbox Code Playgroud)
现在,出于单元测试目的和从这里提取的其他原因(设计无法更改),我必须SomeType根据Condition标签创建值.
但是,我的第一次尝试没有编译:
let inline createSomeType' (someTypeVal : ^T, cond) =
match cond with
| Int -> T1 someTypeVal // warning FS0064: 'T restricted to "int"
| String -> T2 someTypeVal // error FS0001: expected "string" got "int"
Run Code Online (Sandbox Code Playgroud)
更改功能签名createSomeType'< ^T >也无济于事:
error FS0001: expected "int" got 'T
error FS0001: expected "string" got 'T
Run Code Online (Sandbox Code Playgroud)
然后我尝试重载:
type detail =
static …Run Code Online (Sandbox Code Playgroud) 我遇到了这段代码,想知道这行[X]会返回什么:
int add_multiply(int a, int b)
{
int p, q;
p = a + b;
q = a * b;
return (p, q); //X
}
void main()
{
int b, a = add_multiply(1, 2);
b = add_multiply(3, 4);
printf("%d%d", a, b);
}
Run Code Online (Sandbox Code Playgroud)