No function defined in class, but it's there!



1
2
3
4
5
6
7
michael@caitlyn current-ourrpg $ make && ./battle
g++    -c -o ally.o ally.cpp
ally.cpp:19:38: error: no ‘SDL_Surface* Ally::getCurrrentSprite()’ member function declared in class ‘Ally’
 SDL_Surface* Ally::getCurrrentSprite(){ return image; }
                                      ^
<builtin>: recipe for target 'ally.o' failed
make: *** [ally.o] Error 1


This is ally.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
michael@caitlyn current-ourrpg $ cat ally.h
#ifndef ALLY_H
#define ALLY_H

#include "character.h"
#include <SDL/SDL.h>
class AllyJobClass : Job
{
      enum JOBCLASS 
      { 
	 BARD,
	 BLACKBELT,
	 BLACKMAGE,
	 DARKKNIGHT,
	 DEVOUT,
	 DRAGOON,
	 EVOKER,  
	 ONIONKNIGHT, 
	 GEOMANCER, 
	 KNIGHT, 
	 MAGUS, 
	 MONK, 
	 NINJA, 
	 RANGER, 
	 REDMAGE, 
	 SAGE,
	 SCHOLAR, 
	 SUMMONER, 
	 THIEF, 
	 VIKING, 
	 WARRIOR,
	 WHITEMAGE 
      };
   
};

class Ally : public Character
{
   public:
      Ally() { this->image = NULL; }
      Ally(char* name, int jobclass);
      ~Ally();
      void setCurrentSprite(int index);
      SDL_Surface* getCurrentSprite();       


   private:
      enum STATE { FIGHT, WALK, RAISE, STRIKE, HIT, HURT, DEAD};
      SDL_Surface* image;
      
};
#endif 

This is ally.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
michael@caitlyn current-ourrpg $ cat ally.cpp
#include "ally.h"


Ally::Ally(char* n, int jobclass)
{
   Character::setName(n);
   this->image= NULL;
}
Ally::~Ally()
{
}
void Ally::setCurrentSprite(int index)
{
   currentrect->w = 64;
   currentrect->h = 64;
   currentrect->y = 0;
   currentrect->x = index*currentrect->w;
}
SDL_Surface* Ally::getCurrrentSprite(){ return image; }


So why is this happening? I want the code to return the SDL_Surface image. It should be perfectly legal, shouldn't it, even though I have not generated any actual content for the SDL_Surface object???
How many 'rrr's?
SDL_Surface* getCurrentSprite();

SDL_Surface* Ally::getCurrrentSprite(){ return image; }

Spot the difference.
Last edited on
Nevermind. I got it. I moved the definition of getCurrentSprite from ally.cpp to ally.h and it worked. Also, I see in the above listing that Ally:getCurrentSprite has too many 'r's in it. That was probably why. And here I was thinking that I wouldn't learn anything from this experience.
Topic archived. No new replies allowed.