小编Aus*_*ore的帖子

抽象类正在使用它自己的抽象方法?

我正在查看游戏中的一些代码,我遇到了一些我以前没见过的东西,我真的不知道最近发生了什么.

public abstract class Entity
{

    public Entity(World world)
    {
        // irrelevent code
        entityInit();
    }

    protected abstract void entityInit();
}
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?它呼吁时会发生什么entityInit()

java abstract-class abstract abstract-methods

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

在./script第17行没有这样的文件或目录

确切的错误:

$ ./script.pl file.txt  
Can't open file.txt: No such file or directory at ./script.pl line 17. 
Use of uninitialized value in chomp at ./script.pl line 17. 
Username: Password:
Run Code Online (Sandbox Code Playgroud)

我正在编写一个脚本,从命令行获取文件名,然后将其输出写入它:

#!/usr/bin/perl
use warnings;
use strict;
use Term::ReadKey;

my @array;
my $user;
my $pass;

# get login info
print "Username: ";
chomp($user = <>); # line 17
print "Password: ";
ReadMode 2;
chomp($pass = <>);
ReadMode 0;
print " \n";

# ...
# connect to database, and save the info in "@array" …
Run Code Online (Sandbox Code Playgroud)

perl file-io

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

有没有更优雅的方法来找到正确的数字?

我有一个2D数组,作为国际象棋游戏的板.我希望用户输入在Smith Notation中.设置数组的方式是,如果用户说他们想要一块移动到第8行(从用户的角度来看最上面一行),它们就会row[0]在数组中进行交互.因此,为了解决这个问题,我编写了一个函数,将用户的输入转换为数组的正确行.然而,它似乎有点笨重,我想知道如何有更多经验的程序员将解决这个问题.

int convertToCorrectRow(int row)
{
    int newRow;
    switch (row) {
        case 1:
            newRow = 7;
            break;
        case 2:
            newRow = 6;
            break;
        case 3:
            newRow = 5;
            break;
        case 4:
            newRow = 4;
            break;
        case 5:
            newRow = 3;
            break;
        case 6:
            newRow = 2;
            break;
        case 7:
            newRow = 1;
            break;
        case 8:
            newRow = 0;
            break;            
        default:
            assert(false);
            break;
    }
    return newRow;
}
Run Code Online (Sandbox Code Playgroud)

我确实想过翻转数组并将其反向显示给用户,这样当用户与第8行交互时,它们实际上row[7]在数组中进行交互,这将消除对此功能的需求.但是,我仍然想知道解决这个问题的其他方法.在此先感谢您的回复.

c++ case switch-statement

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

Rotating a 2D object drawn with OpenGL

I made a fancy shape with OpenGL and I draw that shape this function:

drawShape(const Point & center, char radius, int points, int rotation)
Run Code Online (Sandbox Code Playgroud)

Inside the function I have code that tells OpenGL where the vertexes are:

glBegin(GL_LINE_LOOP);
  glColor3f(1.0, 1.0, 1.0);
  glVertex2f(center.getX() + 0.0, center.getY() + 1.0);
  // more vertices
glEnd();
Run Code Online (Sandbox Code Playgroud)

现在,当我添加 时glRotatef(rotation, 0.0, 0.0, 1.0),我只希望我绘制的这个形状在屏幕上旋转。但是,如果我将它添加到它上面,glBegin()它会旋转窗口中的所有内容。如果我在对象之间包含所有代码glPushMatrix()glPopMatrix()旋转对象,但围绕窗口中心旋转。如何仅旋转我绘制的对象?

c++ opengl graphics rotation

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

比较两个数组,删除匹配的项目

我有两个数组,@names并且@employees填充了表示名称的字符串. @names是二维的,持有对匿名数组的引用,但我们关心的数据的位置是@names[i][0].我想循环@names查找哪些名称不在@employees.

起初我认为@names向后循环,比较它@employees并删除任何匹配@names将起作用,但我遇到了一些错误.这就是我所拥有的:

for my $i (reverse(0 .. $#names)) {
  foreach my $employee (@employees) {
    if ($names[$i][0] eq $employee) {  # line 67
      splice(@names, $i, 1);
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我遇到这个错误:

在script.pl第67行第2行的字符串eq中使用未初始化的值.

字符串都在数组中定义.所以我猜这是由于我在循环中删除数组中的元素而引起的,但我认为向后循环数组会阻止这样的问题发生.

那我在循环中哪里出错了?此外,我一直在努力解决这个循环,这暗示我的整个思考过程出了问题.有没有更好的方法来做到这一点?

arrays perl

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

取消选择JTable中的选定行

我使用Swing和JTable创建了一个UI.我实现了一个ListSelectionListener通过它,我可以根据表中选定的行获取记录.选择后我无法取消选择该行.

所以基本上我应该能够通过一次单击选择一行,然后我应该可以通过再次单击取消选择该行.

我尝试过使用tableName.getSelectionModel.clearSelection,但我不知道如何查看是否选择了某行.什么会告诉我这个?

我尝试的另一个解决方案是使用鼠标单击侦听器.同样,我无法编写条件来检查鼠标单击是否发生在先前选定的行上.有没有办法让我选择上一行?

我正在使用DefaultTableModel.

java swing jtable listselectionlistener

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

将 h1 置于标题中心?

我试图将其fofam(h1)置于页面的中心。但由于navlogo,我遇到了麻烦。帮助?我已经尝试修复它有一段时间了,但我似乎无法让它发挥作用。我尝试过内联等。

<style>
    header {
        height:300px;
        margin:0 auto;
        background:#21628c;
        font-family:arial;
        text-transform:uppercase;
    }
    div.logo svg{
        float:left;
        padding:10px 30px;
        display:inline-block;
    }
    nav{
        float:right;
        color:#000000;
        display:inline-block;
        padding: 20px 20px;
    }
    nav a{
            margin-left:30px;
            color:black;
    }
    nav a:hover{
        color:white;
        font-size:20px;
    }
    h1{
        color:white;
        font-size:72px;
        text-align:center;
        display:inline-block;
        position:relative;

    }
    h1 span{
        border:10px solid white;
        padding: .2em .5em; 
    }
    p.descripton{
        text-align:center;
        color:white;

    }
</style>
<header>
    <title>Mikhaila</title>
    <div class="logo"><svg...</svg></div>
    <nav>
        <a href="">Mission</a>
        <a href="">Events</a>
        <a href="">Contact Us</a>
    </nav>
    <h1><span>FOFAM</span></h1>
    <p class="descripton">Friends of …
Run Code Online (Sandbox Code Playgroud)

html css css-position

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

这是好风格吗?

我的函数中有一些参数接收并传递相同的值.我应该将所有参数变量命名为相同吗?

例:

// assume numMonth = 12
// assume numYear = 2000

int promptMonth(); // returns numMonth
int promptYear();  // returns numYear

int daysInMonth(int numMonth, int numYear); // numMonth and numYear will always
int daysInYear(int numYear);                // be sent to these.

bool isLeapYear(int numYear);               // daysInYear() and daysInMonth() call
                                            // this function and send it numYear 
                                            // (which would be 2000 in this case).
Run Code Online (Sandbox Code Playgroud)

是否所有这些参数都被命名为相同,因为相同的值被传递给它们?

c++ coding-style parameter-passing

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

分段错误:11 - 它在哪里?

我正在使用gcc编译程序,当我运行时,a.out我收到此错误:

分段错误:11

我认为这与它有关Board::display,但我没有看到它有什么问题..

#include <iostream>

using namespace std;

const bool WHITE = 0;
const bool BLACK = 1;

//-----------------------------

class Piece
{
public:
    // constructors
    Piece();
    Piece(bool color);

    // functions
    char getColor()  const {return color; }
    bool getSymbol() const {return symbol;}

protected:
    bool color;
    char symbol;
};

ostream& operator << (ostream& out, const Piece & piece)
{
    out << piece.getSymbol();
    return out;
}

Piece::Piece() { }

Piece::Piece(bool color)
{
    this->color = color;
}

//-----------------------------

class King …
Run Code Online (Sandbox Code Playgroud)

c++ segmentation-fault

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

理解此对象创建语句

我对Perl不是很熟悉,但我正在使用它来编写一个简单的脚本.此脚本将与Qualys连接,因此在查找有关Qualys API的信息时,我在查看示例代码时发现了此语句.我把它放在Pastebin.com(这里),所以你不必下载它来查看它.如果由于某种原因你想自己下载它,这里有一个指向我想要能够下载源代码的页面的链接(它是"获取地图").

无论如何,这是声明(第261行),让我有点困惑:

$request = new HTTP::Request GET => $url;
Run Code Online (Sandbox Code Playgroud)

我感到困惑的newGET => $url语句的部分.

  1. 我想我大部分都知道new声明的部分是怎么回事,但是如果有人能够解释如何HTTP::Request创建一个LWP::UserAgent有助于澄清这一行的新工作(我在CPAN上看了LWP :: UserAgent,但是"KEY/DEFAULT" "他们在new子程序解释下的表对我来说没什么意义".
  2. 我真的不知道GET => $url声明中发生了什么.我的猜测是它正在分配一个值HTTP::Request或者LWP::UserAgent我找不到任何信息来支持这个想法.

perl object

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

如何删除我创建的这个对象?

以此程序为例:

class Piece
{
public:
    Piece(bool color);

protected:
    bool color;
};

Piece::Piece(bool color)
{
    this->color = color;
}

//-----------------------------

class King : public Piece
{
public:
    King(bool color);
};

King::King(bool color) : Piece(color)
{
    // empty
}

//-----------------------------

class Tile
{
public:
    // constructors/destructors
    Tile(Piece * ppiece, int rrow, int ccol);
    ~Tile();

private:
    Piece * piece;
    int row, col;

};

Tile::Tile(Piece * ppiece, int rrow, int ccol)
{
    this->ppiece = piece;
    this->row = rrow;
    this->col = ccol;
}

//---------------------------

int …
Run Code Online (Sandbox Code Playgroud)

c++ new-operator delete-operator

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

如何安装Py-Moneyed?

我正在尝试使用Django-Money将MoneyField添加到我的 Django 应用程序中。

根据要求,我需要安装py-moneyed v0.4或更高版本。

我检查了py-moneyed但它没有提到如何安装 py-moneyed?

有人可以帮助我在我的环境中安装py-moneyedDjango-Money吗?有没有一个pipeasy_install包可以做到这一点?

python django pip python-module

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