Jump to content
  • Advertisement
Sign in to follow this  
Bluebottel

Struct member not declared

This topic is 3768 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
Ive been thinking in those lines before, but i cant seem to find the answer anyway. Correct me if im wrong, but a->b is the same as (a*).b?

Share this post


Link to post
Share on other sites
(*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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!