-1

I have used c++ and opengl for a while but have never realy dwelled into classes. I am trying to create a Block class for my voxel game however the compiler is giving me the error

block.h:13:7: note: candidate expects 1 argument, 0 provided

Line 13 is line where is create the class. Here is the Block header file:

#ifndef BLOCK_H
#define BLOCK_H

#include <GL/glew.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include "Shader.h"
#include "Camera.h"

using namespace glm;

class Block{
public:
    void render(Camera cam);
    glm::vec3 position;
    Block(glm::vec3 position);  
private:
    void createMesh();
    GLuint VAO, VBO;
    Shader shader;
};

#endif

The complete error:

world.cpp: In constructor ‘World::World(GLFWwindow*)’:
world.cpp:3:32: error: no matching function for call to ‘Block::Block()’
 World::World(GLFWwindow* window)
                                ^
world.cpp:3:32: note: candidates are:
In file included from world.h:9:0,
                 from world.cpp:1:
block.h:17:2: note: Block::Block(glm::vec3)
  Block(glm::vec3 position); 
  ^
block.h:17:2: note:   candidate expects 1 argument, 0 provided
block.h:13:7: note: Block::Block(const Block&)
 class Block{
       ^
block.h:13:7: note:   candidate expects 1 argument, 0 provided

I am also receiving many other similar compiler errors, here is the output:
http://pastie.org/10691691

---EDIT--- Ok, i have shortend the error down a bit. Here is the updated error log: http://pastie.org/10691707

ThatPixelCherry
  • 323
  • 1
  • 4
  • 17
  • 1
    You should also attach the calling code/headers (shader.h etc). From the errors it appears your constructor signature does not match how you are creating it in the code. Perhaps you can see the below: - http://stackoverflow.com/questions/12733888/regarding-c-include-another-class – Prabindh Jan 16 '16 at 05:17

3 Answers3

1

I saw an error saying that Shader does not have a default constructor, i.e Shader::Shader(). For that error, your constructor for your Block class is going to need to construct it in the member initializer list.

For example

Block::Block(glm::vec3 position)
:  m_Shader( "needed shader args" )
{
}

It further looked like you were attempting to construct one of your Blocks somewhere, in a world class?. There too it was complaining about lack of default constructor for Block. If you want default constructor, you must define one in your block class definition. Or you need to initialize your block class in the World class's member initializer list, just like the above example with the shader.

As the compiler suggests, you could also use in class member initializers, but you'd need to turn on C++11 support for that.

grifcj
  • 383
  • 6
  • 15
  • 1
    Unfortunately, I don't know OpenGL, so I can't provide super specific direction. But it seems like you have two constructor options for a shader, one that takes a vertex path and fragment path or the copy constructor. If you know what a vertexPath and fragmentPath are or you have access to the shader you want to use, you need to modify the definition of your Block constructor to pass those in place of the "needed shader args" that I typed above. – grifcj Jan 16 '16 at 05:45
  • 1
    Also, you may want to review this http://www.cplusplus.com/doc/tutorial/classes/ Especially the section on member initializer lists. – grifcj Jan 16 '16 at 05:48
1

Your definition of Block requires an argument of glm::vec3 to be passed during its construction (or a Block itself for copy construction). Your constructor of World appears to not supply such an argument.

jxh
  • 69,070
  • 8
  • 110
  • 193
-1

Turns out I had to also put a empty override constructor in every class. The issue was i was calling a constructor when i created the variables as well as when I was instantiating the object. Here is a quick example:

Shader::Shader(){
    //Do nothing here is it just a override so we declare the variable before creating it.
}

Shader::Shader(char* vpath, char* fpath){
    //Do proper shader stuff here
}
ThatPixelCherry
  • 323
  • 1
  • 4
  • 17