小编sha*_*han的帖子

如何访问std :: list的第一个元素?

我有一份清单std::list<T *> *l;.此列表不为空且具有一些值.我的问题是如何正确访问项目?我不需要遍历列表.我只想要第一个项目.

std::list<T*>::iterator it = l->begin();

if (it != l->end())
{
    // accessing T
    int value = (*it)->value(); // Is this safe?
}
Run Code Online (Sandbox Code Playgroud)

或者我也应该检查是否为空?

if (it != l->end() && (*it))
{
    // accessing T
    int value = (*it)->value();
}
Run Code Online (Sandbox Code Playgroud)

c++ pointers iterator stl list

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

如何用我自己的4x4矩阵更新opengl模型视图矩阵?

我有4x4矩阵用于对象的转换.

float mat44[16];
Run Code Online (Sandbox Code Playgroud)

但我不知道如何使用我的矩阵更新OpenGL ModelView矩阵.我应该使用glTranslatef()/ glRotatef()与我的矩阵中的相关值,还是应该使用glLoadMatrix(),glMultMatrix()?请帮忙.谢谢.

opengl 3d matrix matrix-multiplication

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

基于文件的C++数据库

我想在我的应用程序中使用数据库.但它不应该是基于服务器的数据库(如MySQL).是否有基于文件的C++数据库系统?如果您可以建议非关系数据库,那就更好了.像基于XML文件...

c++ database

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

如何在JTable行中设置自定义对象

我应该首先告诉它,这不是关于渲染表格单元格.

这是我正在使用基于User我的数据库中的对象的2D数组构建的TableModel .

    List<User> userList = userManagerService.getAllUsers();

    /* String[] col_user = {"Username", "Name", "Phone", .... } */
    String[][] data = new String[userList.size()][col_user.length];
    int i = 0;
    for (User user : userList) {
        String[] userdata = new String[col_user.length];
        userdata[0] = user.getUserUsername();
        userdata[1] = user.getUserName();
        userdata[2] = user.getUserPhone();
        userdata[3] = user.getUserNic();
        userdata[4] = user.getUserAddress();
        userdata[5] = user.getUserEmail();

        data[i++] = userdata;
    }

    VstTableItemModel tiModel = new VstTableItemModel(data, col_user);
    dataTable.setModel(tiModel);
Run Code Online (Sandbox Code Playgroud)

我的问题是如何User使用表中的选定行返回一个对象.请注意,我无法创建新User对象并使用行数据填充它.我必须得到被查询的User对象(对象userList).那么,他们用表格行设置对象的方法是什么?

这是我的VstTableItemModel课. …

java user-interface swing jtable tablemodel

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

memcpy()是否使用realloc()?

#inlcude <stdio.h>
#inlcude <stdlib.h>
#inlcude <string.h>

int main() {
    char *buff = (char*)malloc(sizeof(char) * 5);
    char *str = "abcdefghijklmnopqrstuvwxyz";

    memcpy (buff, name, strlen(str));

    while(*buff) {
        printf("%c" , *buff++);
    }

    printf("\n");

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

此代码打印整个字符串"abc ... xyz".但是"buff"没有足够的内存来容纳那个字符串.memcpy()如何工作?它使用realloc()吗?

c buffer memcpy realloc

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

Box不会在Bullet Physics中滚动

正如您在图像中看到的那样,The Box不会滚动,而是在斜坡上滑动.

在此输入图像描述

这是我如何在代码中创建框,

config = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(config);
broadphase = new btDbvtBroadphase();
solver = new btSequentialImpulseConstraintSolver();
bWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, config);
bWorld->setGravity(btVector3(0, -9.8f, 0));

// ...

btTransform t;
t.setIdentity();
t.setOrigin(btVector3(position.x, position.y, position.z));

btBoxShape* box = new btBoxShape(btVector3(size.x, size.y, size.z));
btVector3 inertia(0, 0, 0);
float mass = 10.f;
box->calculateLocalInertia(mass, inertia);

btMotionState* mState = new btDefaultMotionState(t);
btRigidBody::btRigidBodyConstructionInfo cInfo(mass, mState, box);
//cInfo.m_restitution = 0.4f;
//cInfo.m_friction = 0.5f;
btRigidBody* body = new btRigidBody(cInfo);
//body->setLinearFactor(btVector3(1,1,0));
//body->setAngularFactor(btVector3(0,0,1));
m_impl->bWorld->addRigidBody(body);
Run Code Online (Sandbox Code Playgroud)

我尝试了摩擦和其他参数,但结果是一样的.让我知道我在这里做错了什么.

c++ bullet game-engine game-physics

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

将指针传递给新运算符

这段代码意味着什么?根据此链接,无法将指针传递给new运算符.new这里的运算符是默认运算符,而不是重载运算符.请帮忙

LPVOID m_Buffer;
MyClass* mc = new(reinterpret_cast<void*>(m_Buffer)) MyClass;
Run Code Online (Sandbox Code Playgroud)

c++ winapi memory-management

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