标签: compiler-errors

为什么匿名内部类的 Java 中 human.x=10 和 human.test(0) 编译错误?

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);编译错误?

java oop compiler-errors class anonymous-class

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

错误:在“.”之前应有“=”、“,”、“;”、“asm”或“__attribute__” C 程序中的令牌

#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)

c compiler-errors data-structures

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

我该如何解决这些编译错误?

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)

c# compiler-errors

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

Switch-Case不能这样工作吗?

我正在尝试将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)

c# compiler-errors

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

wget:无法解析主机地址“www.cmake.org”

我正在尝试在 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

linux compiler-errors centos cmake

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

为什么我看到“与其类同名的成员函数必须是构造函数”?

我有一个有用的函数,我想将它从独立实用程序转换为 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)

c++ constructor compiler-errors

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

为什么不能将数组文字传递给fwrite?

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)

c arrays compiler-errors fwrite literals

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

#define 的“声明未声明任何内容”错误

我试图定义lllong 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)

c++ macros compiler-errors g++ c++14

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

CS0029 读取用户输入时

我正在尝试编写一个计算器,但出现错误 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# compiler-errors

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

为什么编译不会失败?

正如预期的那样,对于以下程序,C/C++ 编译确实失败并显示“警告:指针和整数之间的比较”:

#include <stdbool.h>
int main(void) { return (int*)42 == true; }
Run Code Online (Sandbox Code Playgroud)

但是,当true文字更改为false. 为什么?

  • 确认:clang-1100.0.33.12,gcc 7.5.0
  • 无法确认:g++ 7.5.0

c c++ compiler-errors compiler-warnings

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