#ifdef BUILDING_DLL
bool gameEntry(SiSE* GE){return true;}
bool gameExit(SiSE* GE){return true;}
#endif
I was hoping that when I compiled my project with the .a and using the dll and without the BUILDING_DLL defined that I would be able to overload these 2 functions and use functions defined in the project..but alas not. The 2 functions are being called constantly causing a loop and hanging the process....can anyone think of a design/method to get around this?
Overloading non member functions - is it possible?
Okay. So I've got the DLL for my game engine, thanks to everyone for all their help with that.
Within the engine I have 2 functions used as tags into a game project, well that's the idea. When building the dll I use:
Quote:Original post by garyfletcher
Okay. So I've got the DLL for my game engine, thanks to everyone for all their help with that.
Within the engine I have 2 functions used as tags into a game project, well that's the idea. When building the dll I use:#ifdef BUILDING_DLLbool gameEntry(SiSE* GE){return true;}bool gameExit(SiSE* GE){return true;}#endif
I was hoping that when I compiled my project with the .a and using the dll and without the BUILDING_DLL defined that I would be able to overload these 2 functions and use functions defined in the project..but alas not. The 2 functions are being called constantly causing a loop and hanging the process....can anyone think of a design/method to get around this?
You can't inherit functions - only class methods.
To do what you want to achieve, I suggest you to use the strategy pattern:
class Strategy{public: // inherit those virtual bool gameEntry(SiSE *GE) = 0; virtual bool gameExit(SiSE *GE) = 0;};// in your DLLbool gameEntry(Strategy *s, SiSE *GE){ if (s) return s->gameEntry(GE); else return true;}bool gameExit(Strategy *s, SiSE *GE){ if (s) return s->gameExit(GE); else return true;}
HTH,
Thanks for that Emmanuel and Anon (Ermm!!!).
I was a little confused about what Emmanuel suggested. I have heard about design patterns, I'm guessing that is what the Stategy pattern is, but haven't really read anything about them yet...perhaps I should.
I solved the problem by passing the functions to the game engine class when I instansiate the Game engine object within the project. That seems to do the trick.
Thanks for trying to help though...much appreciated.
EDIT: The anonymous post seems to have gone???? Maybe I dreamt it?
I was a little confused about what Emmanuel suggested. I have heard about design patterns, I'm guessing that is what the Stategy pattern is, but haven't really read anything about them yet...perhaps I should.
I solved the problem by passing the functions to the game engine class when I instansiate the Game engine object within the project. That seems to do the trick.
Thanks for trying to help though...much appreciated.
EDIT: The anonymous post seems to have gone???? Maybe I dreamt it?
Let's clear up a minor confusion between "overload" and "override":
To "overload" a function means to provide multiple functions with the same name, but different parameters. All functions can be overloaded. For example, the function foo is overloaded here: int foo( int bar ) { ... }
int foo( char * baz ) { ... } To "override" a function means to replace it through inheritance. You can't override non-member functions. For example, the function foo is overridden here: class A
{
int foo( int bar ) { ... }
};
class B : public A
{
int foo( int bar ) { ... }
}; Note that overloaded function have different parameters, but overriden functions have identical parameters.
To "overload" a function means to provide multiple functions with the same name, but different parameters. All functions can be overloaded. For example, the function foo is overloaded here: int foo( int bar ) { ... }
int foo( char * baz ) { ... } To "override" a function means to replace it through inheritance. You can't override non-member functions. For example, the function foo is overridden here: class A
{
int foo( int bar ) { ... }
};
class B : public A
{
int foo( int bar ) { ... }
}; Note that overloaded function have different parameters, but overriden functions have identical parameters.
That should have been...
To "overload" a function means to provide multiple functions with the same name, but different parameters. All functions can be overloaded. For example, the function foo is overloaded here:
To "overload" a function means to provide multiple functions with the same name, but different parameters. All functions can be overloaded. For example, the function foo is overloaded here:
int foo( int bar ) { ... } int foo( char * baz ) { ... }
To "override" a function means to replace it through inheritance. You can't override non-member functions. For example, the function foo is overridden here: class A { int foo( int bar ) { ... } }; class B : public A { int foo( int bar ) { ... } };
In summary, overloaded functions have different parameters, but overriden functions have identical parameters.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement