RPGDXThe center of Indie-RPG gaming
Not logged in. [log in] [register]
 
 
Post new topic Reply to topic  
View previous topic - View next topic  
Author Message
Captain Vimes
Grumble Teddy


Joined: 12 May 2006
Posts: 225
Location: The City Streets

PostPosted: Tue Sep 25, 2007 6:29 pm    Post subject: Back Again. With One More Question. [quote]

Sorry to keep popping in and out of this, but my connection is seriously down (writing this from the school computer lab, got a backpass to Ms. Johns' class). I'm still working on the Space Invaders thing, and it's going well. I've eliminated the [undefined reference to vtable for Sprite] errors (turns out I wasn't defining the destructor, which I'd declared as virtual, so it wasn't saying that is was simply undefined.
Anyway, it's working now. What I'm about to ask is actually a question to make the code more readable.
The vector errors that kept appearing disappeared when I removed this code...

Code:
#ifndef SPRITE_H
#define SPRITE_H

//define sprite code, etc.
#endif


But the vector errors were replaced by a whole new set of errors. I was defining Sprite functions in a separate file ("Sprite.cpp") from Sprite.h, where they were declared with the rest of the class. The errors all said that I was defining the functions multiple times, so I simply moved them back to the header file and deleted Sprite.cpp.
This worked and erased the errors, so now I'm working on the rest of the game, but I'd like to go back to having the functions defined in a separate file. How do I do this without bringing back those multiple definition and/or vector errors?[/code]
_________________
"Sometimes it is better to light a flamethrower than to curse the darkness."
- Terry Pratchett
Back to top  
Ninkazu
Demon Hunter


Joined: 08 Aug 2002
Posts: 945
Location: Location:

PostPosted: Wed Sep 26, 2007 2:36 am    Post subject: [quote]

In header file:
Code:
#ifndef DEFINE_ONCE
#define DEFINE_ONCE

class CClass {
public:
CClass();
void Method1();
private:
int Method2(int param);
int member;
};

#endif


In cpp file
Code:
#include "class.h"
CClass::CClass() {
member = 0;
}

void CClass::Method1() {
member+= Method2(24);
}

int CClass::Method2(int param) {
return (int)(1000 * log(param) / log(2));
}


Is this kinda what your code looks like, or are you doing funky stuff? Your posed problem doesn't have enough info to determine the error. You're only including the header file in other files that need the methods, right? Not something dumb like including the cpp file?
Back to top  
Captain Vimes
Grumble Teddy


Joined: 12 May 2006
Posts: 225
Location: The City Streets

PostPosted: Wed Sep 26, 2007 5:57 pm    Post subject: [quote]

Yep, that's pretty much exactly it. Sorry for not giving more details.

No, I am not including the .cpp file. I'm not that much of a n00b.
_________________
"Sometimes it is better to light a flamethrower than to curse the darkness."
- Terry Pratchett
Back to top  
Ninkazu
Demon Hunter


Joined: 08 Aug 2002
Posts: 945
Location: Location:

PostPosted: Wed Sep 26, 2007 7:07 pm    Post subject: [quote]

Well I can't help without more info then.
Back to top  
Scrim
Mandrake's Little Slap Bitch


Joined: 05 Apr 2007
Posts: 69
Location: Canada

PostPosted: Wed Sep 26, 2007 8:30 pm    Post subject: [quote]

I was scratching my head over this too. What exactly where the errors you were getting when you had the separate source file, and had the header file enclosed in #ifndefs?
Back to top  
Rainer Deyke
Demon Hunter


Joined: 05 Jun 2002
Posts: 672

PostPosted: Thu Sep 27, 2007 7:41 am    Post subject: [quote]

Whenever I have trouble with include guards, it's always one of two things:

1. I reused the same include guard name for two separate header files.

2. I have two header files which mutually include each other.
Back to top  
Post new topic Reply to topic Page 1 of 1 All times are GMT
 



Display posts from previous:   
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum