Results 1 to 9 of 9

Thread: Error LNK2019

  1. #1
    Join Date
    Oct 2008
    Posts
    7

    Error LNK2019

    sorry to have to ask this, but i really cant figure out what could be causing this error.
    error LNK2019: unresolved external symbol "public: void __thiscall Enemy::addGoal(class Character *)" (?addGoal@Enemy@@QAEXPAVCharacter@@@Z) referenced in function "public: void __thiscall Level::addEnemies(int)" (?addEnemies@Level@@QAEXH@Z)

    i kinda have an idea whats causing it but i don't know how to fix it, im guesing its from this line:

    temp->addGoal(player);

    im making that game from the VTMs

    any help would be awesome.

  2. #2
    Join Date
    Mar 2006
    Location
    South Australia
    Posts
    4,521
    Have you implemented the addGoal function in Enemy.cpp?

  3. #3
    Join Date
    Oct 2008
    Posts
    7
    Code:
    #include "enemy.h"
    #include "character.h"
    #include "level.h"
    
    #include <math.h>
    #include <stdlib.h>
    
    Enemy::Enemy(Level *l, DrawEngine *de, int s_index, float x, float y, int i_lives) 
    				: Sprite(l, de, s_index, x, y, i_lives)
    {
    	goal = 0;
    	classID = ENEMY_CLASSID;
    }
    
    bool Enemy::move(float x, float y)
    {
    	int xpos = (int)(pos.x + x);
    	int ypos = (int)(pos.y + y);
    
    	if(isValidLevelMove(xpos,ypos))
    	{
    		//make sure we dont run into any other enemys
    
    		erase(pos.x, pos.y);//erase sprite 
    		pos.x += x;
    		pos.y += y;
    		draw(pos.x, pos.y);//redraw sprite in new location 
    
    		facingDirection.x = x;
    		facingDirection.y = y;
    		return true;
    	}
    
    	return false;
    }
    
    void Enemy::idleUpdate(void)
    {
    	if (goal)
    	{
    		simulateAI();
    	}
    }
    
    void Enemy::simulateAI(void)
    {
    	vector goal_pos = goal->getPosition();
    	vector direction;
    
    	direction.x = goal_pos.x - pos.x;
    	direction.y = goal_pos.y - pos.y;
    
    	float mag = sqrt (direction.x * direction.x + direction.y * direction.y);
    
    	direction.x = direction.x /mag;
    	direction.y = direction.y /mag;
    
    	if (!move(direction.x, direction.y))
    	{
    		while (!move(float(rand() % 3 - 1),float (rand() % 3 - 1)))
    		{
    		}
    	}
    
    }
    thats whats in my enemy.cpp i dont think they showed implementing the addgoal in the enemy.cpp yet but it compiles for them in the VTMs.

  4. #4
    Join Date
    Nov 2006
    Location
    UK
    Posts
    3,774
    Do you have addGoal on any of your classes? (in case you're trying to add it to the wrong thing?)
    Delphi !ROCKS!
    Got a question? Read this first!!!
    "You gotta help us, Doc. We've tried nothin' and we're all out of ideas"

  5. #5
    Join Date
    Oct 2008
    Posts
    7
    i have temp->addGoal(player); in level.cpp
    but addGoal is only defined in enemy.h

    dont i need something like:
    Code:
    void Enemy::addGoal(Character *g)
    {
    }
    in the enemy.cpp?

  6. #6
    Join Date
    Jun 2005
    Location
    NY
    Posts
    1,374
    Yes. You need to define the function.

    Simply having it in a class like:
    Code:
    class Enemy
    {
    public:
        ...other class stuff...
        void addGoal(Character *g);
        ...rest of class...
    };
    Is a function declaration, not a definition. A definition is the actual functional code of the function. That is why you get that linker error, you call the function, it knows that there is a function named that, but it can't find where the function code is. If that makes any sense.

    If you didn't put any addGoal, definition or declaration, you'll get a compiler error instead of a linker error(which they are different).

    so putting:
    Code:
    void Enemy::addGoal(Character *g)
    {
    }
    Will fix that error, the function just won't do anything until you implement the code to add the goal.
    CodeGuru: DLL Tutorial For Beginners by me. Rated 4 1/2 out of 5.

  7. #7
    Join Date
    Nov 2006
    Location
    UK
    Posts
    3,774
    Quote Originally Posted by Nemix View Post
    i have temp->addGoal(player); in level.cpp
    but addGoal is only defined in enemy.h

    dont i need something like:
    Code:
    void Enemy::addGoal(Character *g)
    {
    }
    in the enemy.cpp?
    Yes, I havent seen the videos that far so I wanted to check if you were adding the goal to the right thing was all.

    maybe you missed them adding the blank function?
    Delphi !ROCKS!
    Got a question? Read this first!!!
    "You gotta help us, Doc. We've tried nothin' and we're all out of ideas"

  8. #8
    Join Date
    Oct 2008
    Posts
    7
    yeah, ill just go back and recap. i must of just missed the blank functio.
    TY for your help, just hope that is the prob =D

    Edit:

    yeah i missed a bit which they skimmed over very quickly, i needed to add:
    Code:
    void Enemy::addGoal(Character *g)
    {
    	goal = g;
    }
    Last edited by Nemix; 12-10-2008 at 04:58 PM.

  9. #9
    Join Date
    Nov 2006
    Location
    UK
    Posts
    3,774

    There you go
    Delphi !ROCKS!
    Got a question? Read this first!!!
    "You gotta help us, Doc. We've tried nothin' and we're all out of ideas"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •