c++,opengl,3d , OpenGL cube not being rendered

OpenGL cube not being rendered


Tag: c++,opengl,3d

I'm struggling to get a cube to render in opengl. When I pass in the MVP already calculated to the vertex shader it works fine, but when I pass in the model, view and projection then do the calculation in the vertex shader it doesn't show the cube. I'm also getting error 1282 when I change the vertex shader's uniform types to mat4 instead of vec4.


#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/transform.hpp>
#include <fstream>
#include <stdlib.h>
#include <vector>

GLuint getShader(const char* shaderName, GLenum shaderType) {
    std::cout << "Making shader " << shaderName << std::endl;

    /* Read file */
    std::cout << "Reading shader file" << std::endl;
    std::ifstream shaderFile;
    shaderFile.open(shaderName, std::ios_base::in);

    if (!shaderFile) {
        std::cout << shaderName << " not found" << std::endl;
        return 0;

    std::string line;
    std::string shaderData;
    while (std::getline(shaderFile, line)) {
        shaderData += line + "\n";


    /* Create shader */
    std::cout << "Compiling shader" << std::endl;
    GLuint shader = glCreateShader(shaderType);

    if (shader == 0) {
        std::cout << "Failed to create shader for " << shaderName << std::endl;
        return 0;

    const char *shaderStr = shaderData.c_str();

    glShaderSource(shader, 1, &shaderStr, nullptr);

    /* Check compile status */
    GLint status;
    glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
    if (status != GL_TRUE) {
        GLint logLength;
        glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);

        GLchar *infoLog = new GLchar[logLength + 1];
        glGetShaderInfoLog(shader, logLength, nullptr, infoLog);

        std::cout << shaderName << " failed to compile: " << infoLog << std::endl;
        return 0;

    GLenum error = glGetError();
    if(error != GL_NO_ERROR) {
        std::cout << "Failed making shader program, error " << error << ": " << glewGetErrorString(error) << std::endl;
        return 0;

    return shader;

int end(const char* message) {

    if(message != nullptr) {
        std::cout << message << std::endl;
    return -1;

struct Shader {
    const char* file;
    GLenum type;

    Shader(const char* file, GLenum type) {
        this->type = type;
        this->file = file;

GLuint getShader(Shader& shader) {
    return getShader(shader.file, shader.type);

GLuint getShaderProgram(std::initializer_list<Shader> shaders, std::initializer_list<const char*> binds) {
    /* Create the shader program */
    GLuint shaderProgram = glCreateProgram();
    GLenum error = glGetError();

    if (shaderProgram == 0) {
        std::cout << "Failed to create shader program" << std::endl;
        return 0;
    else if (glIsProgram(shaderProgram) != GL_TRUE) {
        std::cout << "Failed to create shader program" << std::endl;
        return 0;
    else if(error != GL_NO_ERROR) {
        std::cout << "Failed creating shader program, error " << error << ": " << glewGetErrorString(error) << std::endl;
        return 0;

    /* Compile & attach the shaders */
    for(Shader shader : shaders) {
        GLuint glShader = getShader(shader);

        if (glShader == 0) {
            std::cout << "Failed to load shader " << shader.file << std::endl;
            return 0;

        std::cout << "Attaching shader " << shader.file << std::endl;
        glAttachShader(shaderProgram, glShader);

        error = glGetError();
        if(error != GL_NO_ERROR) {
            std::cout << "Failed attaching shader, error " << error << ": " << glewGetErrorString(error) << std::endl;
            return 0;

    /* Bind */
    for(const char* bind : binds) {
        std::cout << "Binding data location " << bind << std::endl;
        glBindFragDataLocation(shaderProgram, 0, bind);

        error = glGetError();
        if(error != GL_NO_ERROR) {
            std::cout << "Failed binding data location, error " << error << ": " << glewGetErrorString(error) << std::endl;
            return 0;

    /* Link to opengl */
    error = glGetError();
    if(error != GL_NO_ERROR) {
        std::cout << "Failed linking shader program, error " << error << ": " << glewGetErrorString(error) << std::endl;
        return 0;

    return shaderProgram;

int main() {
    /* Initial checks */
    if (!glfwInit()) {
        return end("Failed to startup GLFW");

    int major = 3;
    int minor = 3;
    int rev = 0;
    glfwGetVersion(&major, &minor, &rev);

    /* Create the window */
    GLFWwindow *window = glfwCreateWindow(500, 500, "3D world prototyping", nullptr, nullptr);

    if (!window) {
        return end("Failed to create window.");

    glfwMakeContextCurrent(window); //make the window active

    /* Startup GLEW */
    glewExperimental = GL_TRUE;
    if (glewInit() != GLEW_OK) {
        return end("Failed to startup GLEW");

    /* Start OpenGL constants */
    glViewport(0, 0, 800, 600);

    /* Support for multiple shaders without the need to switch attributes */
    GLuint vertexArray;
    glGenVertexArrays(1, &vertexArray);

    /* Shape vectors */
    GLfloat verticies[] = {//X, Y, Z
            -0.5f, -0.5f, -0.5f,
            0.5f, -0.5f, -0.5f,
            0.5f,  0.5f, -0.5f,
            0.5f,  0.5f, -0.5f,
            -0.5f,  0.5f, -0.5f,
            -0.5f, -0.5f, -0.5f,

            -0.5f, -0.5f,  0.5f,
            0.5f, -0.5f,  0.5f,
            0.5f,  0.5f,  0.5f,
            0.5f,  0.5f,  0.5f,
            -0.5f,  0.5f,  0.5f,
            -0.5f, -0.5f,  0.5f,

            -0.5f,  0.5f,  0.5f,
            -0.5f,  0.5f, -0.5f,
            -0.5f, -0.5f, -0.5f,
            -0.5f, -0.5f, -0.5f,
            -0.5f, -0.5f,  0.5f,
            -0.5f,  0.5f,  0.5f,

            0.5f,  0.5f,  0.5f,
            0.5f,  0.5f, -0.5f,
            0.5f, -0.5f, -0.5f,
            0.5f, -0.5f, -0.5f,
            0.5f, -0.5f,  0.5f,
            0.5f,  0.5f,  0.5f,

            -0.5f, -0.5f, -0.5f,
            0.5f, -0.5f, -0.5f,
            0.5f, -0.5f,  0.5f,
            0.5f, -0.5f,  0.5f,
            -0.5f, -0.5f,  0.5f,
            -0.5f, -0.5f, -0.5f,

            -0.5f,  0.5f, -0.5f,
            0.5f,  0.5f, -0.5f,
            0.5f,  0.5f,  0.5f,
            0.5f,  0.5f,  0.5f,
            -0.5f,  0.5f,  0.5f,
            -0.5f,  0.5f, -0.5f

    GLuint shaderProgram = getShaderProgram({
        Shader("vertexShader.glsl", GL_VERTEX_SHADER),
        Shader("fragmentShader.glsl", GL_FRAGMENT_SHADER)
    }, {

    if(shaderProgram == 0) {
        return end("");

        /* Load verticies into memory */
    GLuint vertexBuffer;
    glGenBuffers(1, &vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(verticies), verticies, GL_STATIC_DRAW);

    /* Getting uniform ids */
//    GLint mvpId = glGetUniformLocation(shaderProgram, "mvp");
    GLint projectionId = glGetUniformLocation(shaderProgram, "projection");
    GLint modelId = glGetUniformLocation(shaderProgram, "model");
    GLint viewId = glGetUniformLocation(shaderProgram, "view");

    GLenum error = glGetError();
    if(error != GL_NO_ERROR) {
        std::cout << "Uniform error " << error << ": " << glewGetErrorString(error) << std::endl;
        return end("");
//    else if(mvpId == -1) {
//        return end("MVP ID failed to load");
//    }

    GLint positionAttribute = glGetAttribLocation(shaderProgram, "position");

    if(positionAttribute == -1) {
        std::cout << "Error: position attribute failed to load" << std::endl;
        return end("");

    /* Positioning */
    //FOV, Screen ratio, display range short, display range long
    glm::mat4 projection = glm::perspective(glm::radians(45.0f), 800.0f / 600.0f, 1.0f, 10.0f);
    glm::mat4 model = glm::mat4(1.0f);
    glm::mat4 mvp;

    glm::vec3 camera = glm::vec3(0.0f, 0.0f, 3.0f);
    glm::vec3 cameraLookingAt = glm::vec3(0.0f, 0.0f, 0.0f);
    glm::vec3 cameraPitch = glm::vec3(0.0f, 1.0f, 0.0f);
    float moveSpeed = 0.1f;

    /* Rendering and logic */
    while (!glfwWindowShouldClose(window)) {
        /* Shutdown logic */
        if (glfwGetKey(window, GLFW_KEY_ESCAPE)) {

        /* Clear */
        glClearColor(0.2f, 0.2f, 0.2f, 1.0f);

        /* Logic */
            /* Keypresses */
        if(glfwGetKey(window, GLFW_KEY_W)) {
            camera.z -= moveSpeed;
            cameraLookingAt.z -= moveSpeed;
        else if(glfwGetKey(window, GLFW_KEY_S)) {
            camera.z += moveSpeed;
            cameraLookingAt.z += moveSpeed;

        if(glfwGetKey(window, GLFW_KEY_A)) {
            camera.x -= moveSpeed;
            cameraLookingAt.x -= moveSpeed;
        else if(glfwGetKey(window, GLFW_KEY_D)) {
            camera.x += moveSpeed;
            cameraLookingAt.x += moveSpeed;

        if(glfwGetKey(window, GLFW_KEY_Z)) {
            camera.y += moveSpeed;
            cameraLookingAt.y += moveSpeed;
        else if(glfwGetKey(window, GLFW_KEY_X)) {
            camera.y -= moveSpeed;
            cameraLookingAt.y -= moveSpeed;

        if(glfwGetKey(window, GLFW_KEY_UP)) {
            cameraLookingAt.y += moveSpeed;
        else if(glfwGetKey(window, GLFW_KEY_DOWN)) {
            cameraLookingAt.y -= moveSpeed;

        if(glfwGetKey(window, GLFW_KEY_LEFT)) {
            cameraLookingAt.x -= moveSpeed;
            cameraLookingAt.z -= moveSpeed;
        else if(glfwGetKey(window, GLFW_KEY_RIGHT)) {
            cameraLookingAt.x += moveSpeed;
            cameraLookingAt.z += moveSpeed;

            /* Update position */
        mvp = projection * glm::lookAt(
        ) * model;
        glm::mat4 view = glm::lookAt(

        /* Draw */

            /* Update the position */
//        glUniformMatrix4fv(mvpId, 1, GL_FALSE, &mvp[0][0]);
        glUniform4fv(viewId, 1, glm::value_ptr(view));
        glUniform4fv(modelId, 1, glm::value_ptr(model));
        glUniform4fv(projectionId, 1, glm::value_ptr(projection));

            /* Redraw the position using the verticies */
        glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
        glVertexAttribPointer(positionAttribute, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); //because not just XYZ need to tell opengl the size of the stride

            /* Draw the triangles */
        glDrawArrays(GL_TRIANGLES, 0, 36);

        /* Realtime error checking */
        error = glGetError();
        if(error != GL_NO_ERROR) {
            std::cout << "Error " << error << ": " << glewGetErrorString(error) << std::endl;

    glDeleteBuffers(1, &vertexBuffer);
    glDeleteVertexArrays(1, &vertexArray);
    return end(nullptr);

Vertex shader:

#version 330

uniform mat4 projection; /* view port / perspective */
uniform mat4 model; /* object */
uniform mat4 view; /* camera */
in vec3 position;

void main() {
    gl_Position = projection * view * model * vec4(position, 1.0);


I fixed it!

First thing I had to do was add my buffer binding and attribute pointing into the while loop, I guess you have to tell opengl about them every time you call useProgram.

The second thing was I needed to call glUniformMatrix4fv if I wanted to pass my values in as mat4 (Which they needed to be, instead of vec4).


Confused about returns in stack template

I'm implementing a generic stack (with an array) in C++ and am confused about what to return in this situation: template <class T> T Stack<T>::pop(void) { if (size != 0) { return items[size - 1]; size--; } else { cerr << "Cannot pop from empty stack." << endl; return ???;...

std::condition_variable – notify once but wait thread wakened twice

Here's a simple C++ thread pool implementation. It's an altered version orginated from https://github.com/progschj/ThreadPool. #ifndef __THREAD_POOL_H__ #define __THREAD_POOL_H__ #include <vector> #include <queue> #include <memory> #include <thread> #include <chrono> #include <mutex> #include <condition_variable> #include <future> #include <functional> #include <stdexcept> namespace ThreadPool { class FixedThreadPool { public: FixedThreadPool(size_t); template<class F, class......

segfault accessing qlist element through an iterator

I get a segfault while iterating over a QList. I don't understand what I am doing wrong. I have a QList of Conversation. Inside a Conversation I have a QList of Msg. Below are the class description : Msg class : class Msg { public: Msg(); Msg(const Msg& other); Msg&...

Undefined behaviour or may be something with memset

I was trying to save the binary equivalent of a 32 bit number in an array A. For testing my showbits() function , I choosed 8,9 when I came across this thing: I am facing an unreasonable thing in my code when I am placing memset in the function showbits(),I...

Creating GUI with OpenGL

I am trying to write a Java programm using LWJGL 3 and so far I've made it to creating a window, rendering to it and getting basic input. But I've ran into a problem with creating GUI and namely text fields that my programm requires. I found information that there...

Checking value of deleted object

I asked a question: Detecting if an object is still active or it has been destroyed Considering that I cannot use libraries, there are no good out of the box solutions in C++. So, is it a bad practice to check if the object has been destroyed by analyzing memory...

Type function that returns a tuple of chosen types

I've implemented a type function Tuple that turn a list of My_enum values into an std::tuple of corresponding types: #include <tuple> enum My_enum{ t_int, t_double }; // Bind_type is a type function that given a My_enum returns the corresponding type template<My_enum E> struct Bind_type; template<> struct Bind_type<t_int>{ using type =...

Make a triangle shape in C++

I am trying to print out the shape of a triangle but I am kinda lost... this is what I have so far: #include <iostream> using namespace std; int main() { int i, k, n; cout << "Please enter number of rows you want to see: \n"; cin >> n;...

Method returning std::vector>

As a continuation of a: Thread, I came across a problem with writing a method of a class which returns: std::vector<std::unique_ptr<Object>> I get compiler errors when such a return type is written. There is some problem with delete operand or something ... Generally, I've wanted to write a method which...

how to sort this vector including pairs

I want to sort in ascending order according to the first element of the inner pair, i.e. a in this case. But its not at all sorting. I am not sure if my function func logic is correct. #include<iostream> #include<algorithm> #include<vector> using namespace std; bool func(const pair<int,pair<int,int> >&i , const...

pointer to pointer dynamic array in C++

I've been having bad luck with dynamic pointers when I want to close it. why the application wrote to memory after end of heap buffer? how can I close my array? int main() { . . int **W; W = new int* [n]; for (int i=1; i <= n; i++)...

MFC visual c++ LNK2019 link error

I just don't understand why i can use the public variables on the class but are getting a link error when trying to use the getLicenceRefused method. I wasn't sure if the problem was because of the CString copy constructor problem I have had before so took the parameter out,...

Marshal struct in struct from c# to c++

I have the following structures in C# and C++. C++: struct TestA { char* iu; }; struct TestB { int cycle1; int cycle2; }; struct MainStruct { TestA test; TestB test2; }; C#: [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi, Pack = 1)] internal struct TestA { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 36)] private string iu; public...

How can I tell clang-format to follow this convention?

I would like to have this: if (!enabled) { return; } turned to this: if (!enabled) { return; } (In other words, I want short if-statements on a single line but keep the {} around them) Currently I'm using the following configuration: AllowShortIfStatementsOnASingleLine: true AllowShortLoopsOnASingleLine: true AllowShortCaseLabelsOnASingleLine: true AllowShortFunctionsOnASingleLine: true...

Strings vs binary for storing variables inside the file format

We aim at using HDF5 for our data format. HDF5 has been selected because it is a hierarchical filesystem-like cross-platform data format and it supports large amounts of data. The file will contain arrays and some parameters. The question is about how to store the parameters (which are not made...

opencv window not refreshing at mouse callback

I am trying to draw with mouse move in an opencv window. But when I draw, nothing draws on the window. When I try to close the window from the cross in the topleft(ubuntu), it opens a new window which it should be as I haven't pressed escape, and in...

Issue when use two type-cast operators in template class

I define a template class in which, I define two type-cast operator template <class base_t> struct subclass { base_t base; //any function which defined for 'base_t' can be used with 'subclass<base_t>' operator base_t&() { return base; } //I want 'subclass<base_t>' can be converted to any class which 'base_t' can //I...

ctypes error AttributeError symbol not found, OS X 10.7.5

I have a simple test function on C++: #include <stdio.h> #include <string.h> #include <stdlib.h> #include <locale.h> #include <wchar.h> char fun() { printf( "%i", 12 ); return 'y'; } compiling: gcc -o test.so -shared -fPIC test.cpp and using it in python with ctypes: from ctypes import cdll from ctypes import c_char_p...

OpenGL: Defining variables in shaders

My OpenGL program, using GLSL for shaders, has a simple vertex and fragment shader (given by a tutorial). The vertex shader is: #version 330 layout (location = 0) in vec3 Position; void main() { gl_Position = vec4(0.5 * Position.x, 0.5 * Position.y, Position.z, 1.0); } And the fragment shader is:...

C++ template template

I'm trying to understand C++ template templates by implementing a generic container class. Here is the code: using namespace std; template <typename T, template <typename STORETYPE> class Container> class Store { public: ~Store() {}; Store() {}; void someFunc( const T & ) {}; //... private: Container<T> storage; }; int main(int...

template template class specialization

I am just learning about Template Template class specialisation. Not a big problem to explain in detail. From my understanding std::uniform_int_distribution is a template whereas std::uniform_int_distribution<Type> is the full specialisation of uniform_int_distribution giving a type. I pass this in the specialisation class template as follows below Main class template <template...

C++11 Allocation Requirement on Strings

I had heard that C++11 was going to require strings to be allocated in contiguous memory. I even thought I saw a stack overflow question on it, but I can't seem to find it. I know that in practice both gcc and Visual Studio do allocate strings contiguously, I'm just...

.cpp:23: error: cannot convert ‘std::string’ to ‘const char*’ for argument ‘1’ to ‘int atoi(const char*)’

Here a basic code I'm trying to run But I'm having trouble with stoi (it's c++) I keep getting error: ‘stoi’ was not declared in this scope I tried atoi and strtol with this error .cpp:23: error: cannot convert ‘std::string’ to ‘const char*’ for argument ‘1’ to ‘int atoi(const char*)’...

No match for 'operator*' error

Hello fellow programmers! I was going to write a small program for calculating total pay for different periods of time depending on the amount of hours and the salary that the user enters. I managed to make a small bit of the program but when I try to run it...

Explicit instantiation of class template not instantiating constructor

I'm working on a project in C++ and am having trouble understanding what members of a template class get explicitly instantiated when I explicitly instantiate the template class. I've written the following file, which I then compile using Visual C++ 2008 Express Edition's Release configuration and then pop into a...

Incorrect Polar - Cartesian Coordinate Conversions. What does -0 Mean?

I am getting incorrect conversions from polar to cartesian coordinates and vice versa. My code produces weird points like (1,-0). Im using this calculator to check my conversions. Also one of the conversions is completely wrong when I convert back to cartesian coordinates. Point b: (0,1) => (1,1.5708) => (0,0)...

C++ & Qt: Random string from an array area

In my small Qt application, I want to pick a random string out of an array after I clicked on a button. I've read many threads but nothing works for me. So in my slot there's an array with several strings in it. I also implemented <string>, <time.h> and srand....

Opengl - Is glDrawBuffers modification stored in a FBO? No?

I try to create a FrameBuffer with 2 textures attaching to it (Multi Render Targets). Then in every time step, both textures are cleared and painted, as following code. (Some part will be replaced as pseudo code to make it shorter.) Version 1 //beginning of the 1st time step initialize(framebufferID12)...

Parameters to use in a referenced function c++

I am very confused as to what kind of variables I would put into my function here: names. I am doing a practice problem in a C++ book, because I am learning C++ and am on References and pointers right now, and cannot find a solution. Just for background information,...

Copy text and placeholders, variables to the clipboard

In my application I want generate random numbers or strings with a text in front of it. It is important for me that the text won't appear in my window, but instead gets copied to the clipboard. int randomnumber = rand() % 46 + 1; QClipboard *cb = QApplication::clipboard(); cb->setText("Just...

Implicit use of initializer_list

§[dcl.init.list] 8.5.4/2: The template std::initializer_list is not predefined; if the header <initializer_list> is not included prior to a use of std::initializer_list — even an implicit use in which the type is not named ( — the program is ill-formed. Does that mean this program is ill-formed? #include <vector> int main()...

Validate case pattern (isupper/islower) on user input string

I need to write a program that checks if the user-provided first and last names are correctly typed. The program needs to validate that only the first letter of each name part is uppercase. I managed to write code that checks the first character of the input. So I have...

3 X 3 magic square recursively

I'm trying to find all possible solutions to the 3X3 magic square. There should be exactly 8 solutions. My code gets them all but there are a lot of repeats. I'm having a hard time tracking the recursive steps to see why I'm getting all the repeats. // This program...

Test if string represents “yyyy-mm-dd”

I am working on a program that takes two command line arguments. Both arguments should be dates of the form yyyy-mm-dd. Since other folks will be using this program and it will be requesting from mysql, I want to make sure that the command line arguments are valid. My original...

Passing iterator's element to a function: wrong type of pointer

I'm attempting to solve Project Euler's problem #3 using C++ to gain an understanding of how to use C++ iterators. According to the examples I've seen online, I can use the dereferened iterator as a parameter for cout, and it will print the elements successfully. By that same logic, I...

C++ Isn't this a useless inline declaration?

This is another question about inlining a function. But I will take possible comments and answers right away: Defining a function inside a class makes it inline automatically. The same behaviour can be achieved by marking a function with inline outside of the class. An inline function doesn't have to...

Why are shaders and programs stored as integers in OpenGL?

I'm following the "OpenGL Superbible" book and I can't help but notice that when we create a shader and create the program that we attach the shaders to, we store them as GLuint which are unsigned integers. Why are they stored as numbers? What does the value of the number...

Add more features to stack container

I am using default features(push, pop, top, empty, size) of stack container of STL. If I want to add more features like access an element from middle of stack. How could I do this? Thanks...

How can I access the members of a subclass from a superclass with a different constructor?

I have the following class and typedef: class Object { protected: long int id; public: Object(void); ~Object(void) {}; long int get_id(void); }; typedef map<string, Object> obj_map; And then I have its child: class Image: public Object { private: path full_path; int x; int y; img image; public: Image(path p, int...

How can I convert an int to a string in C++11 without using to_string or stoi?

I know it sounds stupid, but I'm using MinGW32 on Windows7, and "to_string was not declared in this scope." It's an actual GCC Bug, and I've followed these instructions and they did not work. So, how can I convert an int to a string in C++11 without using to_string or...

Translating a character array into a integer string in C++

I was trying to achieve translating a character array into a integer string and corresponding character to their alphabetical order. For instance: A(a) = 0 , Z(z) = 25. string key_char = argv[1]; string key_num; for (int i = 0; i < key_char.length(); i++){ if (isalpha(key_char[i])){ if (islower(key_char[i])){ key_num[i] =...

create vector of objects on the stack ? (c++)

I am creating a temporary vector of pointers to myObject objects. But I am wondering about what happens to the objects I created... { std::vector<myObject *> myVector; myVector.reserve(5); for (int i = 0 ; i < 5 ; ++i){ myVector[i] = new myObject(); } } I assume that at the...

Passing something as this argument discards qualifiers

Using the below code, i get the following compile error: In static member function ‘static std::string ctedata::Record::getDispatcher<std::basic_string<char> >::impl(const ctedata::Record&, const string&)’: /home/jason/CrownTheEmpire/lib/ctedata/data.h:111:38: error: passing ‘const std::map<std::basic_string<char>, std::basic_string<char> >’ as ‘this’ argument discards qualifiers [-fpermissive] return rec.fieldValues_[field]; ^ In file included from /usr/include/c++/5.1.0/map:61:0, from...

Can python script know the return value of C++ main function in the Android enviroment

There are several ways of calling C++ executable programs. For example, we can use def run_exe_return_code(run_cmd): process=subprocess.Popen(run_cmd,stdout=subprocess.PIPE,shell=True) (output,err)=process.communicate() exit_code = process.wait() print output print err print exit_code return exit_code to process a C++ executable program: run_exe_return_code('abc') while abc is created by the following C++ codes: int main() { return 1;...

Same function with and without template

I am trying to understand a piece of code of C++11. A class contains 2 functions as shown below: class abc { public: void integerA(int x); template<typename typ> void integerA(typ x); }; I am unable to understand benefit of declaring 2 same functions. Why not declare only one template function?...

Get an ordered list of files in a folder

I have used boost::filesystem::directory_iterator in order to get a list of all the available files into a given folder. The problem is that I supposed this method would give me the files in alphabetical order, while the results seem pretty random. Is there any fancy way of alphabetically sorting them?...

OpenCV - Detection of moving object C++

I am working on Traffic Surveillance System an OpenCv project, I need to detect moving cars and people. I am using background subtraction method to detect moving objects and thus drawing counters. I have a problem : When two car are moving on road closely them my system detects it...

dispatch response packet according to packet sequence id

I have a third-part server, and I'm writing a dll interface for it, my clients use my dll to communicate with the server. The protocol uses a long tcp connection, all traffic goes from this tcp connection. There could be sending/receiving multiple packets at the same time, like a send_msg...

undefined reference to `vtable for implementation' error

I wrote some c++ files and after compiling with out make file it works fine . But when using make file it pop out some errors . My codes are : include directory files : application.h #ifndef APPLICATION_H #define APPLICATION_H #include "employee.h" #include "employee_data.h" #include "employee.h" ...some defintions here... #endif...