i create game with opengl (c++) and i have namespace in file .h :
namespace SR
{
#include "Geometric.h"
//#include others in this namespace
}
when i create in main.cpp some object and i call method from the object (Geometric) -> it doesnt work ,but when i erase the namespace in .h file :
//namespace SR
//{
#include "Geometric.h"
//#include others in this namespace
//}
it work , why ?.
This is when i erase namespace from .h and call method in .cpp [its work]:
#include "shooting_range.h"
int main(int agrc,char** agrv)
{
Geometric p;
p.getCoordinates();
return 0;
}
This is when i use namespace (error : undefined reference to SR::Geometric::Geometric())
#include "shooting_range.h"
int main(int agrc,char** agrv)
{
SR::Geometric p;
p.getCoordinates();
return 0;
}
And there i try add brackets [error : error: request for member ‘getCoordinates’ in ‘p’, which is of non-class type ‘SR::Geometric()]
#include "shooting_range.h"
int main(int agrc,char** agrv)
{
SR::Geometric p();
p.getCoordinates();
return 0;
}
I don't know why it doesn't work :-( My english is bad i am sorry ... I try to explain the best ... I am confused .
_________- edit : I relocate namespace to geometric.h , but still doesnt work . (request for member ‘getCoordinates’ in ‘p’, which is of non-class type ‘SR::Geometric()) Geometric.h :
#ifndef _GEOMETIC_H_
#define _GEOMETIC_H_
#include <GL/gl.h>
#define MAX_VERTEX 300
struct coordinates
{
GLdouble x,y,z;
GLdouble n_x,n_y,n_z;
GLubyte r,g,b;
};
namespace SR
{
class Geometric
{
public :
int a;
Geometric();
void draw();
void rotate(GLdouble angle,GLdouble x,GLdouble y,GLdouble z);
void translate(GLdouble x,GLdouble y,GLdouble z);
void scale(GLdouble x,GLdouble y,GLdouble z);
coordinates* getCoordinates(); //get all vertex
coordinates getCoordinates(GLint); //get data spacific vertex - if vertex == null => error
GLboolean setCoordinates(coordinates*,GLint); //initialization all vertex through parameters
GLboolean setCoordinates(coordinates,GLint); //change data specific vertex
protected :
GLshort number; //number of vertex, maximal number of vertex is macro MAX_VERTEX
coordinates* vertex;
GLdouble matrix[16];
};
}
#endif // _GEOMETIC_H_
Geometric.cpp
#include "Geometric.h"
SR::Geometric::Geometric()
{
vertex = NULL;
number = 0;
}
coordinates* SR::Geometric::getCoordinates()
{
return vertex;
}
coordinates SR::Geometric::getCoordinates(GLint i)
{
return vertex[i];
}
GLboolean SR::Geometric::setCoordinates(coordinates* vertex,GLint number)
{
if(number <= 0 || number > MAX_VERTEX)
return -1;
if(this->vertex)
delete[] vertex;
this->vertex = new coordinates[number];
this->number = number;
for(int i = 0;i < number;i++)
{
this->vertex[i] = vertex[i];
}
return 0;
}
GLboolean SR::Geometric::setCoordinates(coordinates vertex,GLint i)
{
if(number <= 0 || i >= this->number)
return -1;
this->vertex[i] = vertex;
return 0;
}
#include "shooting_range.h"
main.cpp
int main(int agrc,char** agrv)
{
SR::Geometric p();
p.getCoordinates();
return 0;
}