可能重复:
我有一个类,它有一些成员,如x、y、width和height。在它的构造函数中,我不会这样做:
A::A(int x, int y, int width, int height)
{
x = x;
y = y;
width = width;
height = height;
}
这并没有什么意义,当使用g++ x、y、width和height编译时,它们就变成了奇怪的值(例如,-1405737648)。
解决这些命名冲突的最佳方法是什么?
我的程序要求用户输入一个数字,然后验证该数字是在两个随机生成的数字的范围内还是在该范围之外。变量num应该是用户的猜测,但它一直等于0。我不确定它是否与main中的num =0有关,因为如果不存在=0,我会得到一个“变量可能不被初始化”的错误。 代码: public static int getValidGuess(Scanner get)
{
int num;
System.out.print("Guess a number: --> ");
num = get.nextInt();
retur
为什么下面的代码在g++下编译时没有任何警告或错误?我看到的问题是,在第一行中定义的变量x在if作用域中是可访问的,尽管它被重新定义了。
int main() {
int x = 5;
std::cout << x;
if (true) {
int x = 6;
std::cout << x;
}
}
可能重复:
在C#中,用本地作用域定义为if/ the /loop块的变量与在该块后面定义的变量冲突-请参阅代码片段。一个等价的代码在C/C++和Java下编译得很好。这在C#中是预期的行为吗?
public void f(){
if (true) {
/* local if scope */
int a = 1;
System.Console.WriteLine(a);
} else {
/* does not conflict with local from the same if/else */
int a = 2;
Sy
我是as3的新手。我知道这个错误:
内部名称空间中的定义事件存在冲突。
我用的是相同的编码但场景不同。我换了第二幕。
var mysound:bila =new bila()
这是我第一幕的代码,只有在第一幕中才能成功:
var isItPlaying:Boolean = true;
var lastposition:Number = 0;
var mysound:izhar = new izhar();
var soundchannel:SoundChannel = new SoundChannel();
soundchannel = mysound.play(0,0);// pla
我是PostgreSQL的新手。我有一个调用PostgreSQL数据库的winforms应用程序。id不是传入查询,而是使用PostgreSQL参数化存储过程。我可以对无参数的存储过程执行所有操作并获得返回,但是当我添加参数并执行调用时,我得到一个错误,指出列userId不存在。 userid是参数。 在PostgreSQL上,当创建sp时,我还创建了一个具有相同类型和名称的IN参数。 这里我漏掉了什么? sql很简单: select * from public.users u where u.userid = userid.
我正在做一个项目,我需要创建一个方法,将创建两个不同的紫色斑点,这将在一个不同的程序调用。这是我的代码:
public class PaintablePicture extends Picture
{
public PaintablePicture(String fileName)
{super(fileName);}
public void purpleSplotch(int x,int y)
{
int x=0;
int y=1;
while(x < x*2)
while(y < y*3)
{
Color purple = new Co
我们可以在C中的不同函数中声明相同的局部静态变量吗?
例如:
in function1:
void function1()
{
static int a;
a++;
//dosomething here
}
in function2:
void function2()
{
static int a;
a++;
//dosomething here
}
in function3:
void function3()
{
static int a;
a++;
//dosomething here
}
在本例中,如果我调用function1三次
在以下内容中,
int i{3};
const int j{3};
extern const int k{3};
template <typename T, T&>
void f() {}
int main()
{
f<int, i>(); // OK
f<int const, j>(); // not valid template argument: 'j' has not external linkage
f<int const, k>(); // OK
}
GCC给出了使
当编译一些代码(如下所示的声明)时,我得到错误消息‘编译错误:检测到不明确的名称。SixTables’。我在这里和其他地方都找过了,但找不到任何与我的问题相匹配的东西。似乎是导致此错误的最常见原因,声明两个具有相同名称的变量,或者为函数和从中调用它的sub提供相同的名称,这些都不适用。是的,我知道我可以将名称更改为系统满意的名称,但是(1)我不会知道我做错了什么,(2)我选择这个名称是有原因的-它恰好适合它的目的:-)
Option Explicit
Dim ArmOfService As Byte
Dim CharacterNumber As Long
Dim CurrentTerm As
我有一个全局变量列表,像这样:
int a, b, c, d;
这些变量用在专门计算它们的函数中,例如:
int my_func(string x)
{
//count var a//
}
现在我想使用'a‘和例如'b’作为我以这种方式声明的另一个函数的参数:
int multiplication(int a, int b);
并这样定义:
int multiplication(int a, int b)
{
c = a * b;
return c;
}
当我运行它时,我得到以下错误:
ac.c:75:27: error: declaration shadows a var
声明:
部分方法可以是泛型的。约束放在定义的部分方法声明上,并且可以在实现方法声明上重复。参数和类型参数名称在实现声明中不必与在定义声明中相同。
"Constraints are put on the defining partial method declaration, and may optionally be repeated on the implementing one."和"Parameter and type parameter names do not have to be the same in the implementing declar
我最初尝试使用Do While循环,但结果与while循环相同。用户必须输入一个数字28-31.第一次尝试时,如果用户输入的值正确,它将继续到代码的下一部分。但是,如果用户输入了一个不正确的值,它将再次请求一个数字,但是,不管他们输入了什么,它都会不断重复。
#include <cs50.h>
#include <stdio.h>
int main(void)
{
printf("Days in month: ");
int daysInMonth = GetInt();
while (daysInMont
我是Java新手,遇到了一个OCJA-1.8示例问题,我对此有一些疑问。我需要澄清JVM的这种行为。
public class Test{
static int x=1;//**This is static class level variable**
public static void main(String[] args){
int[] nums={1,2,3,4,5};
for(int x:nums){ // Local variable declared for for-each loop.
System.out.println(x);
考虑以下C++11程序:
翻译单元1:
int x = 3;
int main() {}
翻译单位2:
int x = 4;
这个节目是不良的吗?为什么/为什么不?
gcc抱怨说:
error: multiple definition of `x'
我能看到的唯一相关规则是在3.2.4中:
每个程序都必须包含每一个在该程序中使用的非内联函数或变量的确切定义。
但是x不是odr--在程序中使用。(或者说是?)
这是gcc的窃听器吗?还是我在标准中遗漏了什么?
我最近发现使用using将基类函数导入到派生类的名称空间中(当它被隐藏时)。我试图使用它从基类中导入一个函数,作为派生类中该函数的实现:
class A {
public:
virtual void foo() = 0;
};
class B {
public:
void foo() {
}
};
class C : public A, public B {
public:
using B::foo;
};
int main()
{
C c;
}
这不会编译,因为在C中A::foo()是一个纯虚函数。我希望using B::foo;能实现foo()。为什么不是这
在哪些名称空间中是类型胡枝子名称?请考虑以下代码:
#include <stdio.h>
typedef struct x { // 'x' in tag name space
int x; // 'x' in member name space
int y;
} x; // ??
int main() {
x foo = { 1, 2 };
int x = 3; // 'x' in ordinary identifier name s