标签: declaration

Ruby术语问题:这是一个Ruby声明,定义和赋值,都在同一时间吗?

如果我说:

x ="abc"

这似乎是一个声明,定义和赋值,所有这些都在同一时间,无论我之前是否曾在程序中说过任何关于x的内容.

它是否正确?

我不确定Ruby中用于声明,定义和分配的正确术语是什么,或者由于Ruby中的动态类型,这些东西之间甚至有区别.

@tg:关于你的观点#2:即使x在x ="abc"语句之前存在x,你难道不能将x ="abc"语句称为定义/重新定义吗?

ruby terminology declaration definition

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

如何在C++中将指向变量的指针声明为函数的参数?

我有一个函数,需要一个const D3DVECTOR3 *pos,但我没有理由事先声明这个.对我来说最合乎逻辑的解决方案是使用new:

Function(
    //other parameters,
    new D3DXVECTOR3(x, y, 0));
Run Code Online (Sandbox Code Playgroud)

但是我不知道我会怎么做deleting,在函数中初始化.我的下一个想法是使用&运算符,如下所示:

Function(
    //other parameters,
    &D3DVECTOR3(x, y, 0));
Run Code Online (Sandbox Code Playgroud)

但我不知道这是否是一种有效的方法.(它没有出错,但是有很多东西不能给出非常好的错误).我应该使用new,&还是其他一些我忽略的技术?

c++ pointers declaration new-operator function-parameter

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

在C++/CLI中声明函数时,变量前后符号^和*的含义是什么?

例如:

假设我们有一个名为MyClass的类.

String^ MyClass::GetSomeInfoForExamplePuprs( int InfoNumber ) { }

要么

static String ^GetOtherInfoExample() { }

要么

String ^GetOtherInfoExample(object *Something) { }

我在源代码中看到它,无法弄明白.

variables c++-cli declaration function

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

C++中的声明符

什么是C++中的init-declarator和声明符之间的区别?init-declarator可能出现在init-declarator-list中.例:

int x, y, z;
Run Code Online (Sandbox Code Playgroud)

要么

  int x;
  int y;
  int z;
Run Code Online (Sandbox Code Playgroud)

其中x,y,z可能是init-declarators或我应该说声明者?

c++ declaration language-lawyer

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

java中的奇怪声明

可能重复:
Java中数组初始值设定项内包含尾随逗号的数组

为什么以下语句在java中是正确的:

int[][] a = { {1,2,}, {3,4}};
Run Code Online (Sandbox Code Playgroud)

是否应该因为不必要的逗号而导致编译错误?

java arrays declaration multidimensional-array

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

如何在逗号运算符中包含声明?

我有两个简单的测试线:

cout<<(cout<<"ok"<<endl, 8)<<endl;

cout<<(int i(8), 8)<<endl;
Run Code Online (Sandbox Code Playgroud)

第一行工作,但第二行编译失败

error: expected primary-expression before 'int'
Run Code Online (Sandbox Code Playgroud)

出于某种原因,我确实需要在逗号运算符中声明.更具体地说,我想声明一些变量,获取它们的值,并从我的类构造函数的初始化列表中将它们分配给我的常量类成员.以下显示了我的意图.如果使用逗号运算符无法实现,还有其他建议吗?

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <cstdlib>

using namespace std;

void readFile(const string & fileName, int & a, int & b)
{
    fstream fin(fileName.c_str());
    if (!fin.good()) {cerr<<"file not found!"<<endl; exit(1);}
    string line;
    getline(fin, line);
    stringstream ss(line);
    try {ss>>a>>b;}
    catch (...) {cerr<<"the first two entries in file "<<fileName<<" have to be numbers!"<<endl; exit(1);}
    fin.close();
}

class A
{
    private:
        const int _a; 
        const int _b; …
Run Code Online (Sandbox Code Playgroud)

c++ declaration operators

1
推荐指数
3
解决办法
1236
查看次数

泛型定义

我无法掌握整个泛型声明,即使在阅读了关于Java的书籍中的无数文章和条目之后,它们似乎都没有以简单明了的方式解释它.请任何人解释我的那些?:

class Something<T> {...}
Run Code Online (Sandbox Code Playgroud)

我知道T是什么,并且我理解当我们想要为我们传入的任何类型的Object类型编写通用定义/方法时,我们使用泛型,而是具有特定于一种类型的Object扩展的不同类型的方法,我们写一个可以包括一种或多种类型的通用的(因此大写字母T).但是最让我烦恼的是下一个声明示例:

public <T extends Comparable<T>> void Something{...}
Run Code Online (Sandbox Code Playgroud)

首先; 可比较是一个接口而不是一个类(如果我错了,请纠正我)所以第一个为什么它extends不是implements.现在,为什么它必须被宣布(这整个<T ...>之前的东西)void现在和现在Comparable<T>?那是什么意思?进入的Object类型必须具有implements Comparable<T>?因此,如果我想作为类型参数传递类class Something{...}我将得到一个错误,但传递class Something implements Comparable<T>{...}会没事?请揭开我的神秘面纱:(明天我有一个考试,我不能抓住其他东西而不抓住这一个...... :(

java generics declaration

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

函数返回另一个函数

这个问题可能听起来很傻,但为什么我们不能这样做呢?我的意思是,声明者如下:

void (foo())();
Run Code Online (Sandbox Code Playgroud)

我已经阅读了当前C++标准的8.3.5部分,并没有从它所说的内容中找到它的含义.

这是标准所说的:

在TD的声明中,D表格

D1 ( parameter-declaration-clause ) cv-qualifier-seqopt
ref-qualifieropt exception-specificationopt attribute-specifier-seqopt
Run Code Online (Sandbox Code Playgroud)

并且声明T D1中包含的declarator-id的类型是"derived-declarator-type-list T",D中的declarator-id的类型是"parameter-declarator-type-list function of(parameter-declaration) -clause)cv-qualifierseqopt ref-qualifieropt返回T".

因此,正式地说,从该定义暗示我的declration是一个有效的函数declration.T D1在我的情况下,形式void foo()是一个完全有效的declration.我错过了什么?

c++ declaration language-lawyer

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

在C/C++中,int(*f)(float*)会创建什么?

我有点困惑......有人可以确定评估的顺序以及这里实际声明的内容,可能是指针和我们期望使用这些类型找到的类型吗?

书面解释也足够,一切都很棒.真的没有任何意味着你觉得你可以完全解释这将是多么伟大!

这在C/C++中有什么作用?

int (*f) (float *);
Run Code Online (Sandbox Code Playgroud)

c c++ declaration typecasting-operator

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

C-gcc:没有使用不同的函数声明/实现的编译器警告

我试图弄清楚为什么我的C编译器使用以下(简化的)代码不会给我任何警告/错误。

函数声明没有参数,而函数实现则具有参数:

some.h:

void foo();

some.c:

static uint32_t count = 0; 

void foo(uint32_t num) {
    count += num;
    print("Count: %u");
}
Run Code Online (Sandbox Code Playgroud)

main.c:

foo(100);
foo();
Run Code Online (Sandbox Code Playgroud)

输出:

Count: 100
Count: 100
Run Code Online (Sandbox Code Playgroud)

用于目标构建的编译器:

gcc-arm-none-eabi-4_9-2015q1-20150306-win32
Run Code Online (Sandbox Code Playgroud)

用于目标构建的链接器:

gcc-arm-none-eabi-4_9-2015q1-20150306-win32
Run Code Online (Sandbox Code Playgroud)

编译器标志:

-Wall -Werror -DuECC_CURVE=uECC_secp256r1 -DMEMORY_CHECK -DDEBUG -Os -g3 -DBACKTRACE

c gcc declaration

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