我有一个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方法来解决这个问题.
我试图运行一个简单的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)