小编kif*_*iph的帖子

C++初始化非常量静态成员变量?

我得到了成员变量'objectCount'的资格错误.编译器还返回'ISO C++禁止非const静态成员的类内初始化'.这是主要类:

#include <iostream>
#include "Tree.h"
using namespace std;

int main()
{
    Tree oak;
    Tree elm;
    Tree pine;

    cout << "**********\noak: " << oak.getObjectCount()<< endl;
    cout << "**********\nelm: " << elm.getObjectCount()<< endl;
    cout << "**********\npine: " << pine.getObjectCount()<< endl;
}
Run Code Online (Sandbox Code Playgroud)

这是包含非const静态objectCount的树类:

#ifndef TREE_H_INCLUDED
#define TREE_H_INCLUDED

class Tree
{
    private:
        static int objectCount;
    public:
        Tree()
        {
            objectCount++;
        }
        int getObjectCount() const
        {
            return objectCount;
        }
    int Tree::objectCount = 0;
}
#endif // TREE_H_INCLUDED
Run Code Online (Sandbox Code Playgroud)

c++ static const

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

我尝试在PostgreSQL中插入时间戳值时出错?

我试图插入以下值

('PA', 'Hilda Blainwood', 3, 10.7, 4308.20, '9/8/1974', '9:00', '07/03/1996 10:30:00');
Run Code Online (Sandbox Code Playgroud)

具有以下结构的表alltypes

create table alltypes( state CHAR(2), name CHAR(30), children INTEGER, distance FLOAT,
budget NUMERIC(16,2), checkin TIME, started TIMESTAMP);
Run Code Online (Sandbox Code Playgroud)

弹出以下错误

test=# insert into alltypes VALUES('PA', 'Hilda Blainwood', 3, 10.7, 4308.20, '9/8/1974',
'9:00', '07/03/1996 10:30:00');
ERROR:  INSERT has more expressions than target columns
LINE 1: ...Blainwood', 3, 10.7, 4308.20, '9/8/1974', '9:00', '07/03/199...
Run Code Online (Sandbox Code Playgroud)

postgresql sql-insert

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

如何使用libgdx绘制一条线?

我试图绘制一些使用libgdx调试的行,但我失败了.这是我的代码

public class MainMenu extends Screen implements InputProcessor {

private OrthographicCamera camera;
SpriteBatch myBatch;
ShapeRenderer shapeDebugger;

public MainMenu(Game game) {
    super(game);
    camera= new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.update();}

@Override
public void render(float delta) {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    myBatch.begin();
    stage.draw();
    Gdx.gl10.glLineWidth(10);
    shapeDebugger.setProjectionMatrix(camera.combined);
    shapeDebugger.begin(ShapeType.Line);
    shapeDebugger.setColor(1, 1, 1, 1);
    shapeDebugger.line(2, 2, 5, 5);
    myBatch.end();
    }
}
Run Code Online (Sandbox Code Playgroud)

我从行中得到一个错误

shapeDebugger.setProjectionMatrix(camera.combined);

@ Pranav008

非常感谢你.我没想到我需要启动它.但我有一个真正的问题.我将这条线画到游戏画面的中心.

    Gdx.gl10.glLineWidth(2);
    shapeDebugger.setProjectionMatrix(camera.combined);
    shapeDebugger.begin(ShapeType.Line);
    shapeDebugger.setColor(1, 1, 1, 1);
    shapeDebugger.line(Gdx.graphics.getWidth()/2, 0,Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight());
    shapeDebugger.end();
Run Code Online (Sandbox Code Playgroud)

当我尝试调整屏幕大小时,它不会更新到中心,它会向远处移动.

libgdx

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

我无法在以下代码中打印双精度值?

#include <iostream>
#include <iomanip>

using namespace std;

double distance(double, double);

int main ()
{
    double rate, time, distanceValue;

    cout << fixed << showpoint << setprecision(1);

    cout << "Enter rate" << endl;
    cin >> rate;

    cout << "Enter time" << endl;
    cin >> time;

    distanceValue = distance(rate, time);

    cout << "The distance is " << distanceValue << endl;
}

double distance (double num1, double num2)
{
    return num1 * num2;
}
Run Code Online (Sandbox Code Playgroud)

当我尝试编译它时,我看到一长串错误,我没有错在这里!如果我将方法从double更改为int值,它也可以正常工作!! 为什么??

以下错误:

*> C:\ Users\kifcaliph\Desktop\starting

out with c ++\Chapter6> …

c++ double cout

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

标签 统计

c++ ×2

const ×1

cout ×1

double ×1

libgdx ×1

postgresql ×1

sql-insert ×1

static ×1