class Human {
void eat() {
System.out.println("human eat!");
}
}
public class Demo {
public static void main(String[] args) {
Human human = new Human() {
int x = 10;
public void test() {
System.out.println("test - anonymous");
}
@Override
void eat() {
System.out.println("customer eat!");
}
};
human.eat();
human.x = 10; //Illegal
human.test(); //Illegal
}
}
Run Code Online (Sandbox Code Playgroud)
这段代码为什么会human.x=10;出现human.test(0);编译错误?
#include <stdio.h>
struct point {
int x;
int y;
};
struct rectangle {
struct point upper_left;
struct point lower_right;
};
double calcul_area(struct rectangle a) {
double width = a.lower_right.x - a.upper_left.x;
double height = a.upper_left.y - a.lower_right.y;
return width * height;
}
struct rectangle r;
r.upper_left.x = 3;
r.upper_left.y = 9;
r.lower_right.x = 12;
r.lower_right.y = 2;
int main() {
printf("the size of rectangle is %f", calcul_area(r));
}
Run Code Online (Sandbox Code Playgroud)
这段代码用于计算轴 $x$,$y$ 的矩形面积。我不想谈论代码的想法,但我只是想了解为什么会显示此错误。请注意代码当我在主函数下编写上述部分代码时工作正常,但是当我将其放在主函数之前时我看到错误
struct rectangle r;
r.upper_left.x = 3;
r.upper_left.y = 9; …Run Code Online (Sandbox Code Playgroud) for (int z = 0; z < alParmValues.Count; z++)
{
asd.Add((alParmValues[z].ToString().Split(',')));// asd is list<string>
def.Add(alMethSign[z].ToString().Substring(alMethSign[z].ToString().IndexOf('(') + 1, alMethSign[z].ToString().IndexOf(')') - (alMethSign[z].ToString().IndexOf('(') + 1)).Split(','));// def is list<string>
}
Run Code Online (Sandbox Code Playgroud)
这些是我编译时得到的错误:
Error 7 The best overloaded method match for 'System.Collections.Generic.List<string>.Add(string)' has some invalid arguments
D:\HUTT\Code\HUTT\NUnitClasses\BaseGenerator.cs 1118 18 HUTT
Error 8 Argument '1': cannot convert from 'string[]' to 'string'
D:\HUTT\Code\HUTT\NUnitClasses\BaseGenerator.cs 1118 27 HUTT
Run Code Online (Sandbox Code Playgroud) 我正在尝试将JavaScript开关转换为C#.
我收到了错误 Error 3 Cannot implicitly convert type 'bool' to 'int'
switch (numero)
{
case (numero > -1 && numero < 16):
rtn = list1[numero] + " " + str2;
if (primerDigito != 1)
{
rtn += "s";
}
break;
case (numero > 15 && numero < 30):
if (numero != 20)
{
rtn = list2[primerDigito] + list1[segundoDigito];
}
else
{
rtn = "veinte";
}
rtn += " " + str2 + "s";
break;
case (numero > 29 && numero …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 CentOS 6.2 上安装 cmake,但由于某种原因,我收到此错误消息:\n解析 www.cmake.org... 失败:名称解析暂时失败。\nwget:无法解析主机地址 \ xe2\x80\x9cwww.cmake.org\xe2\x80\x9d。\n这是我写的命令:\nwget http://www.cmake.org/files/v2.8/cmake-2.8.3.tar.gz
\n我有一个有用的函数,我想将它从独立实用程序转换为 RAII 样式的帮助程序类。我对类的定义进行得很顺利,直到我粘贴函数代码并重命名它。此时函数名用红色下划线标出,工具提示说“与其类同名的成员函数必须是构造函数”。
此错误消息没有帮助。我知道我不能编写与类同名的函数。我希望这个函数是一个构造函数。为什么不是?这是怎么回事?
前:
void Useful( int Param ) // works, and is useful
{
// do useful things
}
Run Code Online (Sandbox Code Playgroud)
后:
class Useful
{
void Useful( int Param ) // generates error
{
// do useful things
}
};
Run Code Online (Sandbox Code Playgroud) fwrite({0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0xf3, 0xff, 0x61, 0x00, 0x00, 0x01, 0x8a, 0x49, 0x44, 0x41, 0x54, 0x38, 0x8d, 0xa5, 0x93, 0xb1, 0x72, 0xd4, 0x30, 0x10, 0x86, 0xbf, 0x95, 0xad, 0xcc, 0xc4, 0x30, 0xa4, 0xb9, 0xe6, 0x68, 0x68, 0xd3, 0x50, 0xf3, 0x42, 0xbc, 0x0e, 0xcf, 0xc3, 0x0c, 0x1d, 0x33, 0x69, 0x68, 0xa8, 0xaf, 0x09, 0xc5, 0x51, …Run Code Online (Sandbox Code Playgroud) 我试图定义ll为long long. 但是,这没有编译并引发错误。
我在 Windows 机器上使用 VS Code。我也在使用 gcc 8.2.0 版。
这是代码 -
#include <bits/stdc++.h>
using namespace std;
#define ll long long int;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin >> t;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在编译这个时,我收到了这个错误 -
test.cpp: In function 'int main()':
test.cpp:5:22: error: declaration does not declare anything [-fpermissive]
#define ll long long int;
^~~
test.cpp:12:5: note: in expansion of macro 'll'
ll t;
^~
test.cpp:12:8: error: 't' was not declared in this scope …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个计算器,但出现错误 CS0029。这是代码:
using System;
namespace Calculator
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Calculator\n");
Rechnungplus();
}
static void Rechnungplus()
{
Console.WriteLine("after typing a/(every) number press enter.");
double a = Console.ReadLine();
double b = Console.ReadLine();
double c = a + b;
Console.WriteLine($"\n{a} + {b} = {c}");
}
}
}
Run Code Online (Sandbox Code Playgroud)
我搜索了一个解决方案,我发现了一个有类似问题的人的问题。有人说他/她应该尝试:
double a = (Console.ReadLine());
Run Code Online (Sandbox Code Playgroud)
但这没有用。
正如预期的那样,对于以下程序,C/C++ 编译确实失败并显示“警告:指针和整数之间的比较”:
#include <stdbool.h>
int main(void) { return (int*)42 == true; }
Run Code Online (Sandbox Code Playgroud)
但是,当true文字更改为false. 为什么?