There is an error in the source file below, but I do not understand the meaning of this error code.
expected initializer before 'Render'
What should I do with the initializer that I need before 'Render'?
I want to know what initializer I need before Render
https://stackoverflow.com/questions/41968329/c-error-expected-initializer-before-variablename
https://qiita.com/hmito/items/9d928322ca978319da59
src/Render.hpp:At global scope:
src/Render.hpp:73:36:error:expected initializer before 'Render'
73 | T Render <T>::SpriteVertexAttributeRender <T>::spriteVertex[4] = Rendr::SpriteVertexAttribute {{0,0,0},{0,0}};//SpriteVertexAttribute
| ^~~~~~
make:*** [Makefile:25:obj/Render.o] Error 1
FrameWork Compile Error
rc/Render.hpp:At global scope:
src/Render.hpp:72:1:error:need'typename'before'FrameWork::Render<T>::SpriteVertexAttribute'because'FrameWork::Render<T>'is dependent scope
72 | Render<T>::SpriteVertexAttributeRender<T>::spriteVertex[4] = Render::SpriteVertexAttribute {{0,0,0},{0,0}};//SpriteVertexAttribute
| ^~~~~~~~~
| typename
make:*** [Makefile:23:obj/Render.o] Error 1
#ifndef__RENDER_HPP__
#define__RENDER_HPP__
# include "Component.hpp"
# include "glm/gtc/matrix_transform.hpp"
# include "glm/glm.hpp"
# include <glew/glew.h>
# include <GL/gl.h>
# include <memory>
namespace FrameWork
{
class GameObject;
class Material;
template<typename T>
class Render:public Component <T>
{
public:
static void Init();
Render()
{
glGenVertexArrays (1, & vao);
glGenBuffers (1, & vbo);
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, 4*sizeof(SpriteVertexAttribute), spriteVertex, GL_DYNAMIC_DRAW);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
~Render();
static void SetSpriteAttribute (glm::ivec2s);
virtual void RenderBuffer(const glm::mat4view) = 0;
std::shared_ptr<Material>material;
structureSpriteVertexAttribute
{
float position [3];
floatuv[2];
};
static SpriteVertexAttribute spriteVertex[4];
protected:
GLuint vao;
GLuint vbo;
private:
};
template<typename T>
T Render <T>::SpriteVertexAttributeRender <T>:spriteVertex[4];
// template <typename T>
// Render<T>::SpriteVertexAttributeRender<T>:spriteVertex[4];
}
#endif
#include "Render.hpp"
# include "Material.hpp"
# include "Window.hpp"
# include <iostream>
/*####################################
# initialization
######################################*/
template<typename T>
voidFrameWork::Render<T>::Init()
{
// UV coordinates
spriteVertex[0].uv[0] = 0;
spriteVertex[0].uv[1] = 0;
spriteVertex[1].uv[0] = 0;
spriteVertex[1].uv[1] = 1;
spriteVertex[2].uv[0] = 1;
spriteVertex[2].uv[1] = 0;
spriteVertex[3].uv[0] = 1;
spriteVertex[3].uv[1] = 1;
// vertex coordinates
spriteVertex[0].position[0] = -0.5f;
spriteVertex[0].position[1] = 0.5f;
spriteVertex[0].position[2] = 0;
spriteVertex[1].position[0] = -0.5f;
spriteVertex[1].position[1] = -0.5f;
spriteVertex[1].position[2] = 0;
spriteVertex[2].position[0] = 0.5f;
spriteVertex[2].position[1] = 0.5f;
spriteVertex[2].position[2] = 0;
spriteVertex[3].position[0] = 0.5f;
spriteVertex[3].position[1] = -0.5f;
spriteVertex[3].position[2] = 0;
}
/*####################################
# Reset the vertex attribute of the sprite
######################################*/
template<typename T>
voidFrameWork::Render<T>::SetSpriteAttribute(glm::ivec2s)
{
if((s.x<=0)||(s.y<=0))
{
std::cout<<"Material Error—Incorrect size."<<std::endl;
}
// UV coordinates
spriteVertex[0].uv[0] = 0;
spriteVertex[0].uv[1] = 0;
spriteVertex[1].uv[0] = 0;
spriteVertex[1].uv[1] = 1;
spriteVertex[2].uv[0] = 1;
spriteVertex[2].uv[1] = 0;
spriteVertex[3].uv[0] = 1;
spriteVertex[3].uv[1] = 1;
glm:vec2size;
size.x = (1.0f/Window::context->getSize().x)*s.x;
size.y=(1.0f/Window::context->getSize().y)*s.y;
// vertex coordinates
spriteVertex[0].position[0] = -size.x;
spriteVertex[0].position[1] = size.y;
spriteVertex[0].position[2] = 0;
spriteVertex[1].position[0] = -size.x;
spriteVertex[1].position[1] = -size.y;
spriteVertex[1].position[2] = 0;
spriteVertex[2].position[0] = size.x;
spriteVertex[2].position[1] = size.y;
spriteVertex[2].position[2] = 0;
spriteVertex[3].position[0] = size.x;
spriteVertex[3].position[1] = -size.y;
spriteVertex[3].position[2] = 0;
}
/*####################################
# destructor
######################################*/
template<typename T>
FrameWork::Render<T>::~Render()
{
}
What I want to do is initialize the class variables, so T
at the beginning of the line is a typo (no need).
template<typename T>
T Render<T>::SpriteVertexAttributeRender<T>::spriteVertex[4] = Render::SpriteVertexAttribute {{0,0,0},{0,0}};//SpriteVertexAttribute
The compiler probably says "expected initializer before 'Render'" because Render<T>:spriteVertex[4]
is written in the position where the variable name is expected to have an initializer after it as follows:
variable name of type = initializer;
© 2024 OneMinuteCode. All rights reserved.