Sign in to follow this  
Bluebottel

Struct member not declared

Recommended Posts

Bluebottel    122
Im having an annoying problem with my soon-to-be projectile management code.
#include "stuff/include/GL/glfw.h"
#include "stuff/include/MersenneTwister.h"
#include "stuff/include/soil.h"
#include <iostream>
#include <stdlib.h>
#include <math.h>

using namespace std;

struct Point //coordinate
{
	int x,y,z;
};

struct Projectile
{
	Point coordinates;
	float direction;
	float speed;
	int type;
	int id;
	
};

struct ProjectileList
{
		ProjectileList *nextObject;
		ProjectileList *previousObject;
		Projectile object;
};

class ProjectileManager
{
		
	private:
		ProjectileManager();
		~ProjectileManager();
		
	public:
		void DestroyProjectile(int);
		void MoveProjectile(void);
		int AddProjectile(Projectile*);
		ProjectileList *globalProjectileList;
		ProjectileList *firstProjectile;
	
	
};

ProjectileManager::ProjectileManager()
{
	globalProjectileList = new ProjectileList;
	globalProjectileList->nextObject = NULL;
	globalProjectileList->previousObject = NULL;
	firstProjectile = globalProjectileList;
}

void RandomizeSpread(Projectile*, int, int);

ProjectileManager test;


void RandomizeSpread(Projectile *arg, int direction, int maxAngleOfSpread)
{
    
    MTRand rand;
    int spread = direction;
    
	if (maxAngleOfSpread > 0)
	{
		int spread = rand.randInt(maxAngleOfSpread); // randomize between 0 and maxAngleOfSpread. 0 = dead on.
		double leftOrRightOfDirection = rand.rand(); //Randomize between 0 and 1. 1 means to the left.
		
				
		if (leftOrRightOfDirection == 0) //to the RIGHT of direction
		{
			arg->direction = direction + spread;
			
			if (direction + spread > 360)
			{
				spread = spread - 360; //full circle = 360 degrees.
			}	
		}
		
		else //to the LEFT of direction
		{
			arg->direction = direction - spread;
			if (direction - spread < 0)
			{
				spread = spread + 360; //full circle = 360 degrees.
			}
		}
		
		if (direction + spread > 360)
		{
			spread = spread - 360; //full circle = 360 degrees.
		}
		
	}

	arg->direction = spread;
   
}

int ProjectileManager::AddProjectile(Projectile *arg) // return the id of the projectile
{
	
	globalProjectileList.object = arg;
	globalProjectileList->nextObject = new ProjectileList;
	globalProjectileList->nextObject->previousObject = globalProjectileList;
	globalProjectileList->nextObject->nextObject = NULL;
	globalProjectileList = globalProjectileList->nextObject;
	globalProjectileList.object.id = globalProjectileList->previousObject.object.id + 1;
	
	return globalProjectileList->previousObject.object.id;
	
	
}


void ProjectileManager::MoveProjectile()
{
		
	ProjectileList *temp;
	temp = firstProjectile;
	
	int changeY, changeX;
	
	/*float v = 0;
    
        v = x / temp->object.speed;
        v = asin(v);
        v = (v / 3.14) * 180;
    
        if(x < 0 && y > 0)
        {
            angle = -v;
        }
        else if(x < 0 && y < 0)
        {
            angle = 180 + v;
        }
        else if(x > 0 && y < 0)
        {
            angle = 180 + v;
        }
        else if(x > 0 && y > 0)
        {
            angle = 360 - v;
        }
	
	*/
	
	
	while (temp != NULL)
	{
		glPushMatrix();
			glTranslatef(temp->object.coordinates.x
						,temp->object.coordinates.y
						,temp->object.coordinates.z);
						
			glPushMatrix();
			
				
				
				
			
			glPopMatrix();
		glPopMatrix();
	}
	
	
	
}

void ProjectileManager::DestroyProjectile(int argId)
{
	
	ProjectileList *temp;
	temp = firstProjectile;
	
	while (temp != NULL)
	{
		if (temp->object.id == argId)
		{
			if (temp->nextObject == NULL)
			{
				delete temp;
				temp->previousObject->nextObject = NULL;
				
			}
			
			else if (temp->previousObject == NULL)
			{
				delete temp;
				temp = temp->nextObject;
			}
			
			else
			{
				temp->previousObject->nextObject= temp->nextObject;
				temp->nextObject->previousObject= temp->previousObject;
				delete temp;
			}	
		}
	}	
}

Heres the interesting part, the one that generates errors.
int ProjectileManager::AddProjectile(Projectile *arg) // return the id of the projectile
{
	
	globalProjectileList.object = arg;
	globalProjectileList->nextObject = new ProjectileList;
	globalProjectileList->nextObject->previousObject = globalProjectileList;
	globalProjectileList->nextObject->nextObject = NULL;
	globalProjectileList = globalProjectileList->nextObject;
	globalProjectileList.object.id = globalProjectileList->previousObject.object.id + 1;
	
	return globalProjectileList->previousObject.object.id;
	
	
}

This line globalProjectileList.object = arg; Generates these errors. In member function `int ProjectileManager::AddProjectile(Projectile*)': `object' has not been declared request for member of non-aggregate type before '=' token globalProjectileList is a pointer to the first node in a linked list using this struct
struct ProjectileList
{
	ProjectileList *nextObject;
	ProjectileList *previousObject;
	Projectile object;
};

And 'object' is a Projectile struct, like this
struct Projectile
{
	Point coordinates;
	float direction;
	float speed;
	int type;
	int id;
	
};

The same error (`object' has not been declared) occurs whenever i want to access 'object' with the strange exception of this part
void ProjectileManager::DestroyProjectile(int argId)
{
	
	ProjectileList *temp;
	temp = firstProjectile;
	
	while (temp != NULL)
	{
		if (temp->object.id == argId)
		{
			if (temp->nextObject == NULL)
			{
				delete temp;
				temp->previousObject->nextObject = NULL;
				
			}
			
			else if (temp->previousObject == NULL)
			{
				delete temp;
				temp = temp->nextObject;
			}
			
			else
			{
				temp->previousObject->nextObject= temp->nextObject;
				temp->nextObject->previousObject= temp->previousObject;
				delete temp;
			}	
		}
	}	
}


Thanks in advance
Bluebottel

Share this post


Link to post
Share on other sites
SiCrane    11839
(*a).b

In any case if globalProjectileList is a pointer then this:

globalProjectileList.object = arg;

should be:

globalProjectileList->object = arg;

Share this post


Link to post
Share on other sites
Buklenios    106
It's actually (*a).b

The reason you get this error is because although ProjectileList is a struct, you said it yourself:

Quote:
globalProjectileList is a pointer to the first node in a linked list using this struct


In order to access members of struct through a pointer we have to use the -> instead of otherwise using .

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this