小编Sne*_*med的帖子

迭代映射并使用该对作为参考参数C​​ ++ 11

我有一个std::map.我想迭代它并使用结果作为函数的参数.编译似乎抱怨我的对象是左值,但我无法弄清楚为什么它被认为是左值.

void my_function(std::pair<std::string, std::string>& my_arg){
    //do stuff, modify elements from the pair
}

std::map<std::string, std::string> my_map;
// fill the map with values...

for(auto& element : my_map){
    my_function(element);
}
Run Code Online (Sandbox Code Playgroud)

我可能会使用迭代器来解决这个问题,但我想学习如何用c ++ 11方法来解决这个问题.

c++ stdmap auto c++11

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

当相机完全放在前面时,看不到物体

我试图运行一个简单的OpenGL示例,我面临以下问题.当我将相机完美地放在我的物体前面时,根本不会显示该物体.但是当我移动相机(甚至是0.00001)时,会显示该对象.

class GLWidget : public QGLWidget{
    void initializeGL(){

    glEnable(GL_DEPTH_TEST);

    update_timer_ = new QTimer(this);
    connect(update_timer_, SIGNAL(timeout()), this, SLOT(update()));
    update_timer_->start(0.017);
}

/// @note camera decides renderer size
void resizeGL(int width, int height){
    if (height==0) height=1;
    glViewport(0,0,width,height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
 }

void paintGL(){
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity( );

    gluLookAt(0,0, 10.0,0,0,0,0,0,1);
    glBegin(GL_QUADS);

    glColor3ub(255,0,0);

    glVertex3d(1,1,1);

    glVertex3d(1,1,-1);
    glVertex3d(-1,1,-1);
    glVertex3d(-1,1,1);

    glColor3ub(0,255,0);
    glVertex3d(1,-1,1);
    glVertex3d(1,-1,-1);
    glVertex3d(1,1,-1);
    glVertex3d(1,1,1);

    glColor3ub(0,0,255);
    glVertex3d(-1,-1,1);
    glVertex3d(-1,-1,-1);
    glVertex3d(1,-1,-1);
    glVertex3d(1,-1,1);

    glColor3ub(255,255,0);
    glVertex3d(-1,1,1);
    glVertex3d(-1,1,-1);
    glVertex3d(-1,-1,-1);
    glVertex3d(-1,-1,1);

    glColor3ub(0,255,255);
    glVertex3d(1,1,-1);
    glVertex3d(1,-1,-1);
    glVertex3d(-1,-1,-1);
    glVertex3d(-1,1,-1);

    glColor3ub(255,0,255);
    glVertex3d(1,-1,1); …
Run Code Online (Sandbox Code Playgroud)

c++ opengl qglwidget

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

标签 统计

c++ ×2

auto ×1

c++11 ×1

opengl ×1

qglwidget ×1

stdmap ×1