Thread: function calls

  1. #1
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463

    function calls

    MSVC++V6 isn't letting me pass the struct member foe into my function bulletsort. This is legal, isn't it? I've tried everything I can but nothing is right. The error messages I get are below the code. Does anyone know what I should do?
    Code:
    struct person {int x,	y,move,x_offset,y_offset,foe;};	
    
    int bulletsort(bulleter.foe)
    {
    	int count;
    	if(person bulleter.foe)
    	{
    		for(count=8;count<17;count++)
    		{
    			if(ammo[count].exists=TRUE) return count;
    		}
    		return -1;
    	}
    	else
    	{
    		for(count=0;count<8;count++)
    		{
    			if(ammo[count].exists=TRUE) return count;
    		}
    		return -1;
    	}
    }
    END_OF_FUNCTION(bulletsort);
    
    int fire_bullet(person gunner)
    {
    	int count;
    	if((count=bulletsort(gunner.foe))==-1) return 1;
    	ammo[count].x=gunner.x;
    	ammo[count].y=gunner.y;
    	ammo[count].direction=gunner.move%2;
    	return 0;
    }
    END_OF_FUNCTION(fire_bullet);

    C:\Program Files\Microsoft Visual Studio\MyProjects\ActionGameV2\ActionGameV2.cpp(20 ) : error C2065: 'bulleter' : undeclared identifier
    C:\Program Files\Microsoft Visual Studio\MyProjects\ActionGameV2\ActionGameV2.cpp(20 ) : error C2228: left of '.foe' must have class/struct/union type
    C:\Program Files\Microsoft Visual Studio\MyProjects\ActionGameV2\ActionGameV2.cpp(21 ) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
    C:\Program Files\Microsoft Visual Studio\MyProjects\ActionGameV2\ActionGameV2.cpp(45 ) : error C2065: 'bulletsort' : undeclared identifier

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    I *think* it should look like this (note that that is a big think, because im a C++ guy and not C but neway lol):
    Code:
    int bulletsort(person bulleter.foe)
    {
    	int count;
    	if(bulleter.foe)
    	{
    		for(count=8;count<17;count++)
    		{
    			if(ammo[count].exists==TRUE)
                                                        return count;
    		}
    		return -1;
    	}
    	else
    	{
    		for(count=0;count<8;count++)
    		{
    			if(ammo[count].exists==TRUE)
                                                        return count;
    		}
    		return -1;
    	}
    }
    Last edited by Shakti; 11-09-2003 at 01:08 PM.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    int bulletsort(bulleter.foe)
    Most definately wrong. You have two problems with this single line:
    1) 'bulleter.foe' is a single variable in a structure, not a type of its own.
    2) Even if it were a type, you don't have an actual variable name.

    You want something like:
    Code:
    int bulletsort( struct person somevar );
    {
        if( somevar.foe == SOMETHING_OR_OTHER )
            ...do stuff...
       ...more stuff...
    The way you have it wouldn't be valid in C or C++.

    On a side note, unless ammo is a global variable, it's not going to be available to said function, since you haven't declared it any place.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    thanks, quzah. I thought what I did looked wrong but never saw or read anything on the topic. And yes, ammo is global.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Accurately detecting function calls
    By Mole42 in forum C Programming
    Replies: 5
    Last Post: 05-17-2009, 04:01 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM