标签: compiler-errors

为什么我的代码会给出编译时错误?

我试图得到这个问题,但无法理解为什么它给出编译时错误我的代码是:

#include<stdio.h>
static struct student
{
    int a;
    int b;
    int c;
    int d;
}s1={6,7,8,9},s2={4,3,2,1},s3;
void main()
{
    s3=s1+s2;
    clrscr();
    printf("%d %d %d %d",s3.a,s3.b,s3.c,s3.d);
    getch();
}
Run Code Online (Sandbox Code Playgroud)

c compiler-errors

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

总Python处女,这段代码有什么问题?"检测缩进错误."

这段代码有什么问题,在你问我之前用youtube视频和简短的教程做了这一切.非常感谢有人可以帮我编码,在这种情况下只需要我的Skype,我会加你,我需要这样做!:).

在第253行左右,它说需要"预期的缩进块"我真的不知道该怎么做.

    import pygame, sys, time, random, Globals
from pygame.locals import *

pygame.init()
pygame.mixer.init(frequency=22050, size=-16, channels=10, buffer=4096)

#Classes

class MenuButton(pygame.sprite.Sprite):
    def __init__(self, image, image_dem, x, y):
        self.image = pygame.image.load(image[0]).convert_alpha()
        self.image_over = pygame.image.load(image[1]).convert_alpha()
        self.image_dem = image_dem
        self.x = x
        self.y = y
        self.rect = pygame.Rect(self.x, self.y, self.image_dem[0], self.image_dem[1])
    def setXY(x, y):
        self.x = x
        self.y = y
    def setImage(image, dem):
        self.image = pygame.image.load(image[0]).convert_alpha()
        self.image_over = pygame.image.load(image[1]).convert_alpha()
        self.image_dem = dem

class Sprite(pygame.sprite.Sprite):
    def __init__(self, image, image_dem, x, y):
        self.image = pygame.image.load(image).convert_alpha()
        self.image_dem …
Run Code Online (Sandbox Code Playgroud)

python pygame compiler-errors indentation

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

编译错误

当我尝试编译此代码时

using namespace std;
namespace asf{
inline int operator|(int);
}

asf::operator|(int x){
return (x>1)?x*operator|(x-1):1;
}

int main(){
    cout<<5|;
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

[Error] 'int asf::operator|(int)' must have an argument of class or enumerated type
[Error] ISO C++ forbids declaration of 'operator|' with no type [-fpermissive]
[Error] 'int asf::operator|(int)' should have been declared inside 'asf'
[Error] 'int asf::operator|(int)' must have an argument of class or enumerated type
In function 'int main()':
[Error] expected primary-expression before ';' token
Run Code Online (Sandbox Code Playgroud)

怎么了?请帮忙.

c++ namespaces compiler-errors

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

C++比较字符串的字符

好的,所以输入是一个字符串.当我尝试编译以下代码时,我得到了

c.cpp:42:10: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
Run Code Online (Sandbox Code Playgroud)

为什么?

if(input[i] != ' ')
{   
    char s = input[i];
    if(s == "+")
    {
         ...
    }
}
Run Code Online (Sandbox Code Playgroud)

c++ string compiler-errors char

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

错误:表达式不能用作函数?

我在程序中创建了一个快速方法,使用距离公式计算两点之间的距离,这里是代码:

#include <iostream>
#include <cmath>

using namespace std;

int distanceFormula(int x1, int y1, int x2, int y2) {
    double d = sqrt((x1-x2)^2(y1-y2)^2);
    return d;
}
Run Code Online (Sandbox Code Playgroud)

它给我一个编译器错误,我声明"d"变量说"错误:表达式不能用作函数".这是什么意思?我做错了什么?

c++ compiler-errors

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

在C++程序中使用C头

我有一个包含枚举的C头文件

typedef enum {leaf, operator} my_type;
Run Code Online (Sandbox Code Playgroud)

现在当我尝试在我的C++程序中包含此标题时,我得到错误"'运算符'之前的预期标识符"

我怎么能摆脱它.

c c++ compiler-construction compiler-errors compilation

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

在尝试验证用户输入时,Eclipse不允许我使用else语句

import java.util.Scanner;
import java.util.Random;

public class random {
    public static void main(String[] args) {


    System.out.println("===== CS302 TOOL BOX =====");
    System.out.println("T > COIN TOSS SIMULATOR");
    System.out.println("G > GRADE ESTIMATOR");
    System.out.println("C > COLOR CHALLENGE");
    System.out.println("Q > QUIT");
    System.out.print("Type code letter for your choices: ");    

    String Menuchoices = "TGCQ";
    String initial_input = scanner.next();
    String code_choice = initial_input.toUpperCase();
    boolean code_letter;


    if (code_choice.equals(Menuchoices.substring(0,1))
              ||code_choice.equals(Menuchoices.substring(1,2))
              ||code_choice.equals(Menuchoices.substring(2,3))
              ||code_choice.equals(Menuchoices.substring(3,4)));
                 {System.out.println("success");}
    else {System.out.println("Failure");}

     }
}
Run Code Online (Sandbox Code Playgroud)

Eclipse不会允许我把这个声明放进去.任何想法为什么?

java if-statement compiler-errors

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

Java - 错误:找不到符号

我在Java中运用思考方面遇到了问题.这是代码(这是练习的解决方案).

// object/StorageTest.java
// TIJ4 Chapter Object, Exercise 6, page 90
// Write a program that includes and calls the storage() method defined as a
// code fragment in this chapter.

public class StorageTest {  
    public static void main(String[] args) {
        class StoreStuff {
            int storage(String s) {
                return s.length() * 2;
            }   
        }
        StoreStuff x = new StoreStuff();
        System.out.println(x.storage("hi"));        
    }
}
Run Code Online (Sandbox Code Playgroud)

当我编译它时,我有这个错误:

C:\ Users\Ivan\Desktop> javac StorageTest.java StorageTest.java:5:错误:找不到符号返回(s.lenght()*2); ^符号:方法lenght()位置:类型为String 1的变量s错误

我不明白为什么会这样.

java compiler-errors

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

C++ 11统一初始化(即列表初始化)不使用继承进行编译

struct B { 
  int b; 
  B(int i = 0) : b(i) {};  // constructor
};

struct D : B  {
  int d;
};

int main () {
  D obj = {1};  // <-- error
  // D obj {1}; // <-- error (different)

}
Run Code Online (Sandbox Code Playgroud)

上面的代码没有编译,并给出:

error: could not convert ‘{1}’ from ‘<brace-enclosed initializer list>’ to ‘D’
Run Code Online (Sandbox Code Playgroud)

即使我删除了"构造函数"行也是如此.如果我删除=符号,即D obj {1};它然后给出如下:

error: no matching function for call to ‘D::D(<brace-enclosed initializer list>)’
Run Code Online (Sandbox Code Playgroud)

解决此类问题的正确语法是什么?

c++ inheritance compiler-errors c++11 list-initialization

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

错误:非法启动类型

为什么这一小段代码在第6行和第10行(for循环)中给出了非法的类型错误启动....我找不到任何不匹配的大括号......

class StackDemo{
    final int size = 10;
    Stack s = new Stack(size);

    //Push charecters into the stack
    for(int i=0; i<size; i++){
        s.push((char)'A'+i);
    }
    //pop the stack untill its empty
    for(int i=0; i<size; i++){
        System.out.println("Pooped element "+i+" is "+ s.pop());
    }
}
Run Code Online (Sandbox Code Playgroud)

我实现了Stack类,

java stack compiler-errors

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