小编V S*_*ebi的帖子

不是一个封闭的Java类

我正在尝试制作俄罗斯方块游戏而且我遇到了编译器错误

Shape is not an enclosing class

当我尝试创建一个对象时

public class Test {
    public static void main(String[] args) {
        Shape s = new Shapes.ZShape();
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在为每个形状使用内部类.这是我的代码的一部分

public class Shapes {
    class AShape {
    }
    class ZShape {
    }
}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么 ?

java inner-classes

347
推荐指数
6
解决办法
30万
查看次数

C++ map迭代器问题

我在以下代码中有一个奇怪的错误:

float Student::getAverageMark() const throw (NoMarkException)
{
    int sum = 0;
    int count = 0;
    for(map<string, float>::iterator iter = marks.begin(); iter != marks.end(); ++iter) {
        sum += iter->second;
        count++;
    }
    return sum/count;
}
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,它没有什么不同寻常的,它是一个计算地图中平均标记的简单代码.我在一个在线编译器中对它进行了测试并且它有效,但是当我尝试在我的机器上编译它时(我正在使用带有GNU GCC编译器的CodeBlocks)我收到此错误:

错误:从'std :: map,float> :: const_iterator {aka std :: _ Rb_tree_const_iterator,float >>}'转换为非标量类型'std :: map,float> :: iterator {aka std :: _ Rb_tree_iterator, float >>>''request |

c++ gcc iterator map

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

C++继承获取错误

我在弄清楚这个错误时遇到了一些麻烦.所以我有一个Person类和一个Student子类.

Person类具有以下构造函数:

Person(const string &name)
        {   this->name = name;
        }
Run Code Online (Sandbox Code Playgroud)

Student类具有以下构造函数:

Student::Student(const string &name, int regNo)
{ this->name = name;
  this->regNo = regNo;
}
Run Code Online (Sandbox Code Playgroud)

当我尝试编译Student类时,我得到了构造函数的错误:

在构造函数'Student :: Student(const string&,int)'中:

错误:没有匹配函数来调用'Person :: Person()'

我是C++的新手,所以我不知道为什么会出现这个错误,但它显然与Person的继承有关.

c++ inheritance

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

如何用Java中的第二个字按字母顺序对字符串数组进行排序

我正在处理的任务有点问题.基本上,我有一个文件,学生证和他们的名字采用以下格式:

17987贝丝

17950克拉克

17936亚伦

我把文件的内容放在一个数组中,我需要按名称排序,而不是ID.如果我使用Arrays.sort(myArray)它将按ID自动排序.我很难理解比较器,所以如果你能逐步解释它,对我来说会更容易.谢谢!

java arrays sorting string

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

C++ 不能从类型 bool(class) 转换为 bool

所以我有一个抽象超类 ReadWords,和 3 个子类,FirstFilter、SecondFilter 和 ThirdFilter。

Readwords.h:

#ifndef _READWORDS_H
#define _READWORDS_H

using namespace std;
#include <string>
#include <fstream>
#include <iostream>
#include <cstdlib>

class ReadWords
{   public:

        ReadWords(char *filename);

        void close();

        string getNextWord();

        bool isNextWord();

        virtual bool filter(string word)=0;

        string getNextFilteredWord();

    private:
        ifstream wordfile;
        bool eoffound;
        string nextword;
        string fix(string word);

 };

 #endif
Run Code Online (Sandbox Code Playgroud)

第一个过滤器.h:

#ifndef _FIRSTFILTER_H
#define _FIRSTFILTER_H

using namespace std;
#include <string>
#include <fstream>
#include <iostream>
#include "ReadWords.h"

class FirstFilter: public ReadWords
{   public:
       FirstFilter(char *filename);
       virtual bool filter(string word) …
Run Code Online (Sandbox Code Playgroud)

c++ boolean compiler-errors function

0
推荐指数
1
解决办法
7764
查看次数