Qt的QML语言是否提供任何类型的"严格"模式?特别是,我喜欢有两个功能:
undefined或null(例如,foo = bar何时foo是现有属性但bar未定义,foo.bar何时foo为null)console.assert功能不会使应用程序崩溃).在下面的独立程序中,我for原本期望循环在编译时展开,甚至完全计算,Foo::MyNumbers在链接时不必要:
struct Foo
{
constexpr static auto MyNumbers =
{
3,
28,
200,
};
};
constexpr int getSum(void)
{
auto sum = 0;
for (constexpr auto i : Foo::MyNumbers)
{
sum += i;
}
return sum;
}
Run Code Online (Sandbox Code Playgroud)
然而,即使有-O3,既clang++3.7(从源代码编译之前的3.7版本)和g++5.1给出一个类似的错误; clang说read of non-constexpr variable '__begin' is not allowed in a constant expression,虽然g++说the value of '__for_begin' is not usable in a constant expression.
我真的不能想到任何可以在编译时有用 …
我想过滤一个这样的字符串:'Hello%World'----> List = ['Hello','World']有没有内置函数?
我从这个问题中获取代码并编辑它以通过显式调用其中一个移动构造对象的析构函数来生成段错误:
using namespace std;
struct Foo
{
Foo()
{
s = new char[100];
cout << "Constructor called!" << endl;
}
Foo(const Foo& f) = delete;
Foo(Foo&& f) :
s{f.s}
{
cout << "Move ctor called!" << endl;
f.s = nullptr;
}
~Foo()
{
cout << "Destructor called!" << endl;
cout << "s null? " << (s == nullptr) << endl;
delete[] s; // okay if s is NULL
}
char* s;
};
void work(Foo&& f2)
{
cout << …Run Code Online (Sandbox Code Playgroud) Rust的str类有一个parse返回FromStr对象的方法.parse是模板化的,因此str可以手动指定从中解析的类型,例如"3".parse::<i32>()求值为(Result包含)32位int 的对象3.
但是没有指定类型本身似乎不是一个错误.相反,我在尝试打印生成的(通用/未指定的)FromStr对象时收到错误:
let foo = "3".parse();
match foo
{
Ok(m) => println!("foo: {}", m),
Err(e) => println!("error! {}", e)
}
Run Code Online (Sandbox Code Playgroud)
这并没有给第一线的错误; 相反,我收到以下错误:
<anon>:24:12: 24:13 error: unable to infer enough type information about `_`; type annotations or generic parameter binding required [E0282]
<anon>:24 Ok(m) => println!("foo: {}", m),
Run Code Online (Sandbox Code Playgroud)
(这里,第24行是带的线Ok(m).)
那么这是什么m?或者是"无法推断出足够的类型信息"错误实际上是由于实际上parse在没有类型说明符的情况下无法调用,并且编译器只是在Ok实际类型实际存在的第一行之前才捕获错误用过的?
我想让 ScrollView 的滚动条比默认值更宽,但我看不到任何width属性,即使是ScrollViewStyle元素frame组件的一部分。
#include <stdio.h>
#include <string.h>
#include "prac.h"
#define MYNAME "Butter"
int main() {
int numberOfKids;
int weight;
int shirt;
printf("If I eat a Watermelon I will weigh %d lbs \n", weight + numberOfKids+ shirt );
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我编译并运行程序,结果是1; 虽然我预计它是0.当我单独检查每个变量的值时,权重变量的值是1.有人可以解释为什么特定变量结果不是0吗?我是C的新手,想要尝试基础知识,以便更深入地了解C的细微差别.任何帮助都将受到赞赏.