为什么C++ 11使" delete
d"函数参与重载决策?
为什么这有用?或者换句话说,为什么它们被隐藏而不是被完全删除?
为了防止复制类,您可以非常轻松地声明私有复制构造函数/赋值运算符.但你也可以继承boost::noncopyable
.
在这种情况下使用boost有什么优点/缺点?
使用以下使用boost :: asio的代码.
#include <boost/asio.hpp>
using boost::asio::ip::tcp;
class SocketTest
{
private:
boost::asio::io_service& mIOService;
tcp::acceptor mAcceptor; // Comment this line
public:
SocketTest(boost::asio::io_service& io_service)
: mIOService(io_service)
, mAcceptor(io_service, tcp::endpoint(tcp::v4(), 8080)) // Comment this line
{
}
};
Run Code Online (Sandbox Code Playgroud)
如果您对两个标记的行进行注释,则编译器(Visual Studio 2010)在/ W4上进行编译时会发出以下警告.
warning C4512: 'SocketTest' : assignment operator could not be generated
Run Code Online (Sandbox Code Playgroud)
是什么让这两条线如此特别?为什么它们的存在允许生成赋值运算符?
我有这个代码的问题:
// Make it Non Copyable
FileLogger (const FileLogger &) = delete;
FileLogger &operator= (const FileLogger &) = delete;
Run Code Online (Sandbox Code Playgroud)
我需要解决这个错误:
Error 1 error C2059: syntax error : ';'
Error 2 error C2238: unexpected token(s) preceding ';'
Run Code Online (Sandbox Code Playgroud)
在上面发布的相同代码行中,此错误发生16次,语法相同.
我为OpenGL 3.3创建了一个Mesh类,当我使用非默认构造函数创建类时,它在我创建对象时创建顶点时工作正常.
但是,我现在想要通过将它们放在向量中来动态创建多个对象,所以我必须添加一个默认构造函数,我使用相同的函数来设置缓冲区数据,就像使用其他构造函数一样...但是它不起作用.据我所知,这是因为它存在于向量中,但它与构造函数有关,或者事后缓冲区数据会被创建.我真的不太确定.
这是我的课程.(当我创建一个有效的网格时,我用参数调用构造函数,当它不起作用时,我构造一个没有参数的网格并调用"changeMesh"函数)
mesh.h
#ifndef MESH_H
#define MESH_H
#include <iostream>
#include <vector>
#include <GL/glew.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
class mesh
{
public:
mesh();
mesh(std::vector<GLfloat> vertices, std::vector<GLuint> triangles, GLuint shaderProgram);
~mesh();
void changeMesh(std::vector<GLfloat> vertices, std::vector<GLuint> triangles, GLuint shaderProgram);
void render();
void Translate(glm::vec3 addVector);
void Rotate(glm::vec3 rotVector, GLfloat angle);
protected:
private:
GLuint vertexArrayObject, vertexBuffer, elementBuffer, shaderProgram;
std::vector<GLfloat> vertices;
std::vector<GLuint> indices;
glm::mat4 transform;
void setUpMesh();
void bindVertices();
};
#endif // MESH_H
Run Code Online (Sandbox Code Playgroud)
mesh.cpp
#include "../include/mesh.h"
mesh::mesh(std::vector<GLfloat> vertices, std::vector<GLuint> indices, GLuint shaderProgram) …
Run Code Online (Sandbox Code Playgroud) c++ ×5
c++11 ×3
boost ×2
boost-asio ×1
class ×1
mesh ×1
noncopyable ×1
opengl ×1
visual-c++ ×1
warnings ×1