在C++ 0x(哦!读取C++ 11)中,我们有自动类型推断.令我好奇的一件事是我无法创建一系列自动变量.例如:
auto A[] = {1, 2, 3, 4}; // Error!
Run Code Online (Sandbox Code Playgroud)
有什么想法可能被禁止了吗?
我是初学者,我正在按照一本书做练习.下面是我的代码,我得到了这个
"Missing partial modifier on declaration of type 'Windowsform.Form1'; another partial declaration of this type exists".
我该怎么办?我的代码如下:
using System;
using System.Windows.Forms;
namespace Windowsform
{
public class Form1 : Form
{
private TextBox txtEnter;
private Label lblDisplay;
private Button btnOk;
public Form1()
{
this.txtEnter = new TextBox();
this.lblDisplay = new Label();
this.btnOk = new Button();
this.Text = "My Hellowin app!";
//txtEnter
this.txtEnter.Location = new System.Drawing.Point(16, 32);
this.txtEnter.Size = new System.Drawing.Size(264, 20);
//lblDisplay
this.lblDisplay.Location = new System.Drawing.Point(16, 72);
this.lblDisplay.Size = …Run Code Online (Sandbox Code Playgroud) 我猜我只会使用UIKIT_EXTERN,如果我的项目中有可能使用该变量的C++代码.
如果是这种情况,用UIKIT_EXTERN声明所有外部可用的常量是否安全?
为什么我不再看到这个?
我有一个类,我想要一些值为0,1,3,7,15的位掩码,......
所以基本上我想声明一个常量int的数组,例如:
class A{
const int masks[] = {0,1,3,5,7,....}
}
Run Code Online (Sandbox Code Playgroud)
但编译器总会抱怨.
我试过了:
static const int masks[] = {0,1...}
static const int masks[9]; // then initializing inside the constructor
Run Code Online (Sandbox Code Playgroud)
有关如何做到这一点的任何想法?
谢谢!
所以我以前的一个考试有这个问题,到现在为止我一直在读你不需要任何语言的声明?
哪个是对的?如果没有声明,C++会出错,还是会运行?
我想在foreach之外添加一个变量,我应该在foreach循环中访问该变量
<table class="generalTbl">
<tr>
<th>Date</th>
<th>Location</th>
</tr>
@int i;
@foreach (var item in Model)
{
i=0;
<tr>
<td>
@Html.DisplayFor(modelItem => item.DueDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.location)
</td>
</tr>
}
</table>
Run Code Online (Sandbox Code Playgroud)
上面的例子我添加了@int i; 在foreach之外我尝试在foreach中访问它,就像i = 0; 但它显示" 当前上下文中不存在名称'i' "
如何访问循环内的变量?
我目前正在教同事.Net,他问我一个困扰我的问题.
我们为什么要申报?
如果var是隐式类型,为什么我们甚至要声明?
Animal animal = new Animal();
Run Code Online (Sandbox Code Playgroud)
变
var animal = new Animal();
Run Code Online (Sandbox Code Playgroud)
可能成为
animal = new Animal();
Run Code Online (Sandbox Code Playgroud)
隐式类型仍然意味着这是一个静态类型的变量.
如果为变量分配了两种不同的类型,如果它们不共享基类(除了对象),则可能是编译器错误.
是否有技术原因无法完成或风格上我们喜欢有没有
[basic.link]/6
在块作用域中声明的函数的名称和由块作用域
extern声明声明的变量的名称具有链接.如果存在具有相同名称和类型的链接的实体的可见声明,忽略在最内部封闭命名空间范围之外声明的实体,则块范围声明声明该实体并接收先前声明的链接.如果存在多个这样的匹配实体,则该程序是不正确的.否则,如果未找到匹配的实体,则块范围实体将接收外部链接.[示例:Run Code Online (Sandbox Code Playgroud)static void f(); static int i = 0; // #1 void g() { extern void f(); // internal linkage int i; // #2 i has no linkage { extern void f(); // internal linkage extern int i; // #3 external linkage } }
i此程序中有三个对象.具有内部链接的对象由全局范围内的声明引入(第1行),具有自动存储持续时间的对象并且没有由第2行上的声明引入的链接,以及具有静态存储持续时间和由声明引入的外部链接的对象在第3行. - 末端的例子]
我对这一段有两点评论:
static int i = 0;全局范围内的声明在包含声明的块(#3)中不可见extern int i;.因此,我们只能说后一种宣言具有外部联系,即我们不能将其与宣言#1联系起来.static int i;被声明#3视为可见,则根据段落中的文本,块作用域声明声明相同的实体并接收前一声明的链接,即内部链接,而不是外部链接,如实施例中所述.我在这里错过了什么?
在下面的代码中,为什么变量i没有赋值1?
#include <stdio.h>
int main(void)
{
int val = 0;
switch (val) {
int i = 1; //i is defined here
case 0:
printf("value: %d\n", i);
break;
default:
printf("value: %d\n", i);
break;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我编译时,我会收到一个警告,即i尽管int i = 1;它已经初始化,但仍未进行初始化
$ gcc -Wall test.c
warning: ‘i’ is used uninitialized in this function [-Wuninitialized]
printf("value %d\n", i);
^
Run Code Online (Sandbox Code Playgroud)
如果val = 0,那么输出是0.
如果val = 1或其他任何东西,那么输出也是0.
请向我解释为什么i声明变量但在开关内没有定义.标识符 …
我以前见过这个问题,但它们似乎没有涵盖这个特定的用例(或者它们没有工作/帮助)
import {Route} from 'vue-router';
export const detailRoute = {
path: '/detail/:id',
component: Detail,
props: (route: Route) => ({
state: route.query.state
})
};
Run Code Online (Sandbox Code Playgroud)
detailRoute使用Route,我正在导入,但我想作为命名导入{Route}它不起作用?是否有不同的/更好的方法来做到这一点?我也尝试export {Route};过,但这没有用.
tsconfig.json:
{
"compilerOptions": {
"target": "ES2017",
"module": "ES2015",
"moduleResolution": "Node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"allowSyntheticDefaultImports": true,
"noEmitHelpers": true,
"importHelpers": true,
"pretty": true,
"alwaysStrict": true,
"declaration": true,
"declarationDir": "./types",
"lib": [
"DOM",
"ES2017",
"DOM.Iterable",
"ScriptHost"
],
"baseUrl": "./client",
"paths": {
"styles/*": ["./app/core/styles/*"],
"core/*": ["./app/core/*"],
"components/*": ["./app/components/*"],
"containers/*": ["./app/containers/*"],
"assets/*": ["./assets/*"], …Run Code Online (Sandbox Code Playgroud) declaration ×10
c++ ×4
c# ×3
c ×2
extern ×2
.net ×1
arrays ×1
asp.net-mvc ×1
c++11 ×1
c++14 ×1
clr ×1
const ×1
foreach ×1
form-control ×1
module ×1
objective-c ×1
partial ×1
razor ×1
types ×1
typescript ×1
variables ×1
visibility ×1
winforms ×1