using structs as input arguments

Started by
5 comments, last by eskimo456 13 years, 4 months ago
Hi

Sorry more struct questions. I have now managed to create some structs that get the information and calculate the information I would like initially.

My problem is now I would like to take in a struct into a function in another cpp.

I get an error C2027,error C2061, error C2660 It says undefined type, and syntax error identifier.

I am going from my enviroment class

header
class Enviroment{public:	struct Wall{	float X1;	float Z1;	float X2;	float Z2;};	//struct that holds walls normalsstruct NormalArray{	float X1;	float Y1;	float Z1;	float X2;	float Y2;	float Z2;};struct NormalizedWall{	float X;	float Y;	float Z;};	//function prototype	static Wall WallPos(float wallPosition[]);	static NormalArray GetNormal(float xNormal1,float yNormal1,float zNormal1,float xNormal2,float yNormal2,float zNormal2);void drawWater(int StartXwater, int StartYwater, int StartZwater, int EndXwater, int EndYWater, int EndZWater, int waterPosition);	static void drawWall(float wallPosition[],Boat_Pos playerBoat);	static float * initArray(float wallArray[]);	static void InitiliseEnviroment(float wallPosition[]);	//static Enviroment::NormalizedWall InitiliseEnviroment(float wallPosition[]);	GLuint water;	GLuint wall;private:};


and trying to use it as an input to my collision class
static class Collision{public:	Collision(){}	~Collision(){}			void DrawSphere(int x1,int z2, int radius);	static void DrawBox(int posX1, int PosX2, int posY1, int posY2, int posZ1, int posZ2);	static bool BoundingBox(float wall[],Boat_Pos playerBoat);	int boxPos(int posX1, int posX2,int posZ1,int posZ2);	static double DotProduct(int Value1X, int Value2X,int Value1Y, int Value2Y, int Value1Z, int Value2Z);	double CrossProduct(double U1, double V1, double U2, double V2, double U3, double V3);		//this is where my error is         static float * CalculateNormal(Enviroment::NormalArray normalArray);         //this is where my error is	static void NormaliseNormal(float normalArray[],float corner[]);	static float PointToPlaneTest(Boat_Pos player,float pointOnPlane[],float normalValues[]);		static float PlaneEquation(float point1[],float point2[], float point3[],float point[]);		static bool BarryCentricEquation(float triA[],float triB[], float triC[],float point[]);		double posX1;	double posX2;	double posY1;	double posY2;	double posZ1;	double posZ2;	bool collision;	bool bccCollision;	float dist;	//static float normal[3];	private:};


Do I need to import my struct seperate to my class?

[Edited by - eskimo456 on December 11, 2010 5:21:56 PM]
Advertisement
Did you include the header before you defined the Collision class? That's the only thing I can think you're missing. If you posted a complete example instead of just two stray class definitions it would be easier to tell what you might be doing wrong.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

Sorry I'm always worried about posting loads of code.

As far as I can see I have included the headers required

My full Enviroment header is
#pragma once#include <windows.h>		// Header File For Windows#include <gl\gl.h>			// Header File For The OpenGL32 Library#include <gl\glu.h>			// Header File For The GLu32 Library#include "tgaload.h"#include "console.h"#include "Collision.h"#include "Boat_Pos.h"class Boat_Pos;class Enviroment{public:	struct Wall{	float X1;	float Z1;	float X2;	float Z2;};	//struct that holds walls normalsstruct NormalArray{	float X1;	float Y1;	float Z1;	float X2;	float Y2;	float Z2;};struct NormalizedWall{	float X;	float Y;	float Z;};	//function prototype	static Wall WallPos(float wallPosition[]);	static NormalArray GetNormal(float xNormal1,float yNormal1,float zNormal1,float xNormal2,float yNormal2,float zNormal2);	void drawWater(int StartXwater, int StartYwater, int StartZwater, int EndXwater, int EndYWater, int EndZWater, int waterPosition);	static void drawWall(float wallPosition[],Boat_Pos playerBoat);	static float * initArray(float wallArray[]);	static void InitiliseEnviroment(float wallPosition[]);	//static Enviroment::NormalizedWall InitiliseEnviroment(float wallPosition[]);	GLuint water;	GLuint wall;private:};


My full header for my Collsion is
#pragma once#include <windows.h>		// Header File For Windows#include <gl\gl.h>			// Header File For The OpenGL32 Library#include <gl\glu.h>			// Header File For The GLu32 Library#include "console.h"#include "Boat_Pos.h"#include "Calculation.h"#include "Enviroment.h"class Boat_Pos;class Enviroment;static class Collision{public:	Collision(){}	~Collision(){}			void DrawSphere(int x1,int z2, int radius);	static void DrawBox(int posX1, int PosX2, int posY1, int posY2, int posZ1, int posZ2);//draw bounding boxes	static bool BoundingBox(float wall[],Boat_Pos playerBoat);//check bounding collision	int boxPos(int posX1, int posX2,int posZ1,int posZ2);//calculate box position	static double DotProduct(int Value1X, int Value2X,int Value1Y, int Value2Y, int Value1Z, int Value2Z);	double CrossProduct(double U1, double V1, double U2, double V2, double U3, double V3);	//were problem is		static float * CalculateNormal(Enviroment::NormalArray wallToCalculate);	static void NormaliseNormal(float normalArray[],float corner[]);	static float PointToPlaneTest(Boat_Pos player,float pointOnPlane[],float normalValues[]);		static float PlaneEquation(float point1[],float point2[], float point3[],float point[]);		static bool BarryCentricEquation(float triA[],float triB[], float triC[],float point[]);		double posX1;	double posX2;	double posY1;	double posY2;	double posZ1;	double posZ2;	bool collision;	bool bccCollision;	float dist;	//static float normal[3];	private:};


This is where my error is occouring

I am actucally running it in my Enviroment class cpp file
#include "Enviroment.h"Enviroment::Wall Enviroment::WallPos(float wallPosition[]){	Wall wall;	wall.X1 = wallPosition[0];	wall.Z1 = wallPosition[1];	wall.X2 = wallPosition[2];	wall.Z2 = wallPosition[3];	std::cout<<"this is my struct "<<wall.X1<<std::endl;	std::cout<<"this is my struct "<<wall.Z1<<std::endl;	std::cout<<"this is my struct "<<wall.X2<<std::endl;	std::cout<<"this is my struct "<<wall.Z2<<std::endl;	return wall;};Enviroment::NormalArray Enviroment::GetNormal(float xNormal1,float yNormal1,float zNormal1,float xNormal2,float yNormal2,float zNormal2){	NormalArray wallNormal;	wallNormal.X1 = xNormal1;	wallNormal.Y1 = yNormal1;	wallNormal.Z1 = zNormal1;	wallNormal.X2 = xNormal2;	wallNormal.Y2 = yNormal2;	wallNormal.Z2 = zNormal2;	return wallNormal;}void Enviroment::drawWater(int StartXwater, int StartYwater, int StartZwater, int EndXwater, int EndYWater, int EndZWater, int waterPosition){		if(waterPosition == 0)	{	water = tgaLoadAndBind("waterr.tga", TGA_ALPHA);	glEnable(GL_TEXTURE_2D);	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);	glBindTexture(GL_TEXTURE_2D, water);		glPushMatrix();	glBegin(GL_POLYGON);	glTexCoord2f(0,0); glVertex3f(StartXwater, 0, StartZwater);	glTexCoord2f(50,0);glVertex3f(EndXwater, 0, StartZwater);	glTexCoord2f(50,100);glVertex3f(EndXwater, 0, EndZWater);	glTexCoord2f(0,100);glVertex3f(StartXwater, 0, EndZWater);	glEnd();	glDisable(GL_BLEND);	glDisable(GL_TEXTURE_2D);	glPopMatrix();	}	if(waterPosition == 1)	{			water = tgaLoadAndBind("waterr.tga", TGA_ALPHA);	glEnable(GL_TEXTURE_2D);	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);	glBindTexture(GL_TEXTURE_2D, water);		glPushMatrix();	glBegin(GL_POLYGON);	glTexCoord2f(0,0); glVertex3f(StartXwater, 0, StartZwater);	glTexCoord2f(0,300);glVertex3f(EndXwater, 0, StartZwater);	glTexCoord2f(100,300);glVertex3f(EndXwater, 0, EndZWater);	glTexCoord2f(100,0);glVertex3f(StartXwater, 0, EndZWater);	glEnd();	glDisable(GL_BLEND);	glDisable(GL_TEXTURE_2D);	glPopMatrix();	}}void Enviroment::drawWall(float wallPosition[], Boat_Pos playerBoat){			glPushMatrix();	glBegin(GL_POLYGON);		glColor3f(0.7,0.7,0.7);		glTexCoord2f(0,0); glVertex3f(wallPosition[0], 0, wallPosition[1]);		glTexCoord2f(1,0); glVertex3f(wallPosition[0], 3, wallPosition[1]);		glTexCoord2f(1,1); glVertex3f(wallPosition[2], 3, wallPosition[3]);		glTexCoord2f(0,1); glVertex3f(wallPosition[2], 0, wallPosition[3]);glEnd();	}void Enviroment::InitiliseEnviroment(float wallPosition[]){		Enviroment::Wall wallToNormalise = Enviroment::WallPos(wallPosition);	std::cout<<"Wall Position 1 is "<<wallToNormalise.X1<<std::endl;	std::cout<<"Wall Position 2 is "<<wallToNormalise.Z1<<std::endl;	std::cout<<"Wall Position 3 is "<<wallToNormalise.X2<<std::endl;	std::cout<<"Wall Position 4 is "<<wallToNormalise.Z2<<std::endl;	Enviroment::NormalArray wallNormal;	/*wallNormal.X1 = wallToNormalise.X1;	wallNormal.Z1 = wallToNormalise.Z1;	wallNormal.X2 = wallToNormalise.X2;	wallNormal.Z2 = wallToNormalise.Z2;*/	         //this is where I am using my collision	Collision::CalculateNormal(wallNormal);}


If you would like any further code please let me know. I am only using the code in this section though. This is being called in the init() function in the main.

Can you post the exact error messages?
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
You have a circular dependency problem. See problem two in this article.
yep sorry that is the full code

the problem code is in my Collision header file
#pragma once#include <windows.h>		// Header File For Windows#include <gl\gl.h>			// Header File For The OpenGL32 Library#include <gl\glu.h>			// Header File For The GLu32 Library#include "console.h"#include "Boat_Pos.h"#include "Calculation.h"#include "Enviroment.h"class Boat_Pos;class Enviroment;//class Enviroment::NormalArray;  static class Collision{public:	Collision(){}	~Collision(){}        static float * CalculateNormal(Enviroment::NormalArray normalArray);private:};



the errors I get is "undefined type Enviroment" error code C2027 in visual studio 2010. I'm guessing it cant find Enviroment::NormalArray to allow it to be a return type? The other error is related saying "syntax error: identifier NormalArray".

I am using it in this my Enviroment CPP file
void Enviroment::InitiliseEnviroment(float wallPosition[]){Collision::CalculateNormal(wallNormal);}


The function is defined like this
float * Collision::CalculateNormal(Enviroment::NormalArray normalArray){		float ux = normalArray.X1 - normalArray.X1;	float uy = normalArray.Y2 - normalArray.Y1;	float uz = normalArray.Z1 - normalArray.Z1;	float vx = normalArray.X2 - normalArray.X1;	float vy = normalArray.Y2 - normalArray.Y1;	float vz = normalArray.Z2 - normalArray.Z1;	float tempNormal[3];	tempNormal [0] = ((vy*uz) - (vz*uy))*-1;	tempNormal [1] = ((vz*ux) - (vx*uz));	tempNormal [2] = ((vx*uy) - (vy*ux));	std::cout<<"The normal1 is "<<tempNormal [0]<<std::endl;	std::cout<<"The normal2 is "<<tempNormal [1]<<std::endl;	std::cout<<"The normal3 is "<<tempNormal [2]<<std::endl;	return tempNormal;	}


When I do normalArray. it brings up a list of all my possible options etc so I am assuming that this is working fine.

I am only gettin 2 errors both I mentioned earlier in the header file.
Quote:Original post by SiCrane
You have a circular dependency problem. See problem two in this article.


Awsome I have had a look at the article and it suggests removing my #include and just having my class Enviroment;

I have done this in both classes having my class Enviroment and class Collision in the .h files. I have then included he #include "Enviroment.h" and #include "Collision.h" in my .cpp file as it says in the document.

I still get the errors I did earlier???

As my struct is in a class do I need to do something like
class Enviroment::NormalArray;

This topic is closed to new replies.

Advertisement