标签: declaration

声明一个数组并单独初始化它

我想做的事:

int[] array;

...


array = {2, 7, 9};
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点?

当有人在同一时间声明和初始化时,它又称为什么?我只是把它想象为硬代码初始化

java arrays initialization declaration

-2
推荐指数
1
解决办法
1318
查看次数

模板化代理设计模式

我有一个简单且可重现的代码,看起来像这样:

template <typename T>
class Proxy {
private:
    Wrap<T> &self; // If I comment this, it will work
public:
    Proxy() {}
};

template <typename T>
class Wrap {
    T *p;
public:
    Proxy<T> foo() {
        return Proxy<T>();
    }
};

int main()
{
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

'Wrap'没有命名类型

如果我评论Wrap<T> &self,那么它会起作用,但这不是我需要的.我需要Wrap<T>成为Proxy班上的一员.我怎样才能做到这一点?

c++ templates declaration forward-declaration

-2
推荐指数
1
解决办法
88
查看次数

何时在C#中声明有关效率/速度的变量

我正在运行一些完全为效率而构建的实现.我对这个主题还不是很有经验,并且想知道何时最好地声明变量.我的代码的以下部分特别是:

//Variables not declared in the next part are declared here (like xx, y1, x1.....)
    for(s = 0; s < this.Width; s++)
        {
            y = ymin;
            for(z = 0; z < this.Height; z++)
            {
                x1 = 0;
                y1 = 0;
                looper = 0;
                while(looper < curMaxIter && Math.Sqrt((x1 * x1) + (y1 * y1)) < 2)
                {
                    looper++;
                    xx = (x1 * x1) - (y1 * y1) + x;
                    y1 = 2 * x1 * y1 + y;
                    x1 = …
Run Code Online (Sandbox Code Playgroud)

c# variables performance declaration cpu-speed

-2
推荐指数
1
解决办法
91
查看次数

差异Scala类声明

我想问下面这两个类声明之间有什么区别.

class Person(name: String, age: Int)
Run Code Online (Sandbox Code Playgroud)

要么

class Person() {
  var name: String = ""
  var age: Int = 0
}
Run Code Online (Sandbox Code Playgroud)

scala class declaration

-2
推荐指数
1
解决办法
75
查看次数

c#中预期的一元运算符

当我提到

char operator;
Run Code Online (Sandbox Code Playgroud)

它给出了c#中预期的一元运算符错误.

所以当它提到extern时,android中的默认值是'\ u0000'

c# declaration character unary-operator

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

检查是否创建了对象C++

我有以下代码 -

string classNeeded;//set to either "Max" or "Min"

if(strcmp(classNeeded, "Max") == 0)
{

    Maximum maxi;//object of class Maximum declared

}
else
{

    Minimum mini;//object of class Minimum declared

}

while(/*Conditions*/)
{

    //Some processing
    //Use maxi or mini depending on which one is declared

}
Run Code Online (Sandbox Code Playgroud)

我需要检查是否声明了maxi并使用它,或者如果没有声明,请使用mini.如何在C++ Visual Studio 2005中检查是否声明了对象?

PS:我是VS2005 C++编码的新手

c++ visual-studio-2005 class declaration object

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

这个数组在C中是否可行?还有其他办法吗?

我在C中声明了一个大小为150X150X150的数组.在编译程序以获得相同大小的数组时,编译器没有给出任何错误或警告.但是当我尝试运行它时,程序停止响应.

void main(){
 int i,j,k;
 char giv[150][150][50],tar[150][150][50];
 for(int i=0;i<150;i++)
 {
  for(j=0;j<150;j++)
  {
   for(k=0;k<50;k++)
    cin>>giv[i][j][k];
  }
 }
}
Run Code Online (Sandbox Code Playgroud)

有没有办法可以创建一个150*150*150的数组而不会导致运行时错误?编辑:我知道多维数组工作.这不是编译错误.它是一个运行时错误,其原因是我无法精确定位.

c arrays declaration

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

为什么在函数原型之后需要使用分号

为什么我们int add(int,int)在第二行语句后使用分号.

#include<stdio.h>
int add(int,int);
int main()
{
int a,b,c;
scanf("%d %d",&a,&b);
c=add(a,b);
printf("The sum of the 2 numbers is %d",c);
return 0;
}
int add(int x,int y)
{
int sum;
sum=x+y;
return sum;
}
Run Code Online (Sandbox Code Playgroud)

c declaration function function-prototypes

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

-5
推荐指数
1
解决办法
112
查看次数

为什么此代码中的`bar`没有静态存储持续时间?

代码优先:

#include <stdio.h>

void foo()
{
        static int bar;
}

int main()
{
        bar++;
        return 0;
}
Run Code Online (Sandbox Code Playgroud)

编译器(Clang)抱怨:

static.c:10:2: error: use of undeclared identifier 'bar'
Run Code Online (Sandbox Code Playgroud)

该语句static int bar;中是否应该foo()给出bar静态存储持续时间,这使得它在main函数之前声明并初始化?

c static scope declaration

-7
推荐指数
1
解决办法
66
查看次数

有效功能声明

我有一个抽象的C++问题,我和某人就此问题争论过:

其中哪一项可能是有效的函数声明:

int f ( int i=0, int j );
int f (int j, void k);
int f (int i, int u=0 );
int f (int * = 0);
Run Code Online (Sandbox Code Playgroud)

c++ methods declaration

-7
推荐指数
1
解决办法
142
查看次数