Skip to main content
gamedev.net
🔒 Locked

identifiers not recognized..

Started by kewur 2 replies 700+ views
Original Post
kewur
kewur
hello guyz i'v been working on a problem on my code for an hour now and it is driving me crayz .. if u like to just compile it for your self and see the errors. It does not recognize a type i've done . and there are some 'double undeclared identifier' ? lol.. if u guyz can show me where im doing it wrong i'd be glad.. this is a typical linked list structure btw





#include <iostream>
//#include "soldier.h"
#include "Soldier.h"

class linklist
{
private:

	
	struct node
	  {
	  public:
		  Soldier *sptr;
		  node *next;
		
		  double coolDown;
		  
	  }*p;


public :

	linklist();
	void append ( Soldier *ptr , double atckRate);
	void del( Soldier *ptr);
	int count();
	~linklist();
	
};


linklist::linklist(){

	 p = NULL;

}

void linklist::append(Soldier &ptr, double atckRate)
{

   node *q,*t;


   if ( p == NULL){
 
      p = new node;
	  p->sptr = ptr;
	  p->coolDown = atckRate;
	  p->next = NULL;


   }
	
   else {

        q = p;

		while( q->next != NULL){

            q = q->next;

		}

		t = new node;
		t->sptr = ptr;
		t->coolDown = atckRate;
		q->next = t;



   }

}


void linklist::del(Soldier &ptr)
{
     node *q,*r;
   
	 q = p;

	 if(q->sptr == ptr){

		 p = q->next;
		 delete q;

		 return;


	 }
   
	 while (q!=NULL){
 
		 if(q->sptr == ptr)
		 {
			p = q->next
			delete q;
			return;
		 } //if


           q = q->next;




	 } //while



//endofdel
} 


int linklist::count()
{
     node *q;
   int c=0;
   for( q=p ; q != NULL ; q = q->next )
        c++;

   return c;
}


linklist::~linklist()
{
     node *q;
   if( p == NULL )
        return;

   while( p != NULL )
   {
        q = p->next;
      delete p;
      p = q;
   }
}



the soldier header

 
#ifndef __SOLDIER_H
#define __SOLDIER_H


#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
//#include "gameloop.h"
//#include <LoggingUtil.h>   
class Soldier
{
public:

    float maxHealth;
	float currentHealth;
	float Damage;
	float moveSpeed;
	const bool flying;
	const bool swimming;
	int kills;
	int armor;
	std::string	 Name;
	double x,y,z;
	double range;
	std::string Busy;
	double attackRate;
	int boost;


public:

	void attack(Soldier *soldier1 , Soldier *soldier2);
	bool inRange(Soldier *soldier1 , Soldier *soldier2);
	void updateTimer();

};


bool Soldier::inRange(Soldier *soldier1 , Soldier *soldier2){

	//range between two lines.
	if(sqrt(pow(((soldier2->x)-(soldier1->x)),2)+ pow((soldier2->y)-(soldier1->y) , 2)+ pow((soldier2->z)-(soldier1->z), 2)) <= soldier1->range){

		return true;
	}

	else 
		
		return false;

}

void Soldier::updateTimer(){

	// TODO

}




void Soldier::attack(Soldier *soldier1, Soldier *soldier2){
	
	soldier1->Busy					= "attack";


	if(soldier1->Busy == "attack") {

	if(soldier2->currentHealth > 0)
	{

	
		if(inRange(soldier1 , soldier2)){

		soldier2->currentHealth -= soldier1->Damage;

		


	}

		else{
		// TO-DO
		//move towards soldier2
			}
	}
	}




}
#endif






thanks guyz in advance..
matchu
matchu
Your append and del functions takes pointers in the declaration, but references in the implementation...

hope that helps !
Zahlman
Zahlman
Quote:
Original post by kewur
this is a typical linked list structure btw


No. The "typical linked list structure" is std::list. Don't waste time trying to make things work when there is already a working version sitting right there.
kewur
kewur
thnx for the headsup guyz!


btw i didnt know there was a built in linked list in C++ so thank you as well

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.