Original Post
Hi guys, I've moved onto my book concerning game engines. I'd got as far as I could with my last book but have caved in and bought an easier C++ book to learn with. I believe it is called Effective C++, and has good reviews so might be a bit more helpful.
For now though I've decided to press on with the reason I decided to get better at C++ in the first place - my game engine book.
Check out the following code:
Hmm... first things first. This takes place within I believe a static library that is used to initialise a DLL. Basically an object that implements an interface is created inside a DLL and it uses an interface defined within this static library. I'm sort of au fait with this bit but I'm not au fait with the syntax or why the author has chosen some of it. Here we go!
1)The extern keyword if I remember correctly has some effect on the compiler. I think it is necessary to have these things declared here so the file can be compiled but they cannot fully 'exist' here or there will be (I think) a linker problem where it finds two things where it should only find one and cannot resolve the discprency. I'd appreciate it if anyone can tell me if I'm correct here. Thanks.
2)WHat does the "C" part do? The author states that this "exports the functions in plain C-style without C++ name mangling" - "The overhead of object orientation forces C++ to twist around the function names and parameter lists a bit, but we don't want to worry about that and so we enforce plain C usage of those functions here". WHAT? So is he suggesting that there is some inherent flaw within C++ and C++ compilers that makes the basic functional modus operandi of the language useless without clever tricks and hacks? I don't think so somehow. SO what is he trying to achieve here? And what does any of that mean?
3)
That's it for now. ANy help anyone can offer would be appreicated cheers! :oD
For now though I've decided to press on with the reason I decided to get better at C++ in the first place - my game engine book.
Check out the following code:
extern "C"{ HRESULT CreateRenderDevice(HINSTANCE hDLL, ZFXRenderDevice** pInterface); typedef HRESULT (*CREATERENDERDEVICE) (HINSTANCE hDLL, ZFXRenderDevice** pInterface); HRESULT ReleaseRenderDevice(ZFXRenderDevice** pInterface); typedef HRESULT (*RELEASERENDERDEVICE) (ZFXRenderDevice** pInterface);}1)The extern keyword if I remember correctly has some effect on the compiler. I think it is necessary to have these things declared here so the file can be compiled but they cannot fully 'exist' here or there will be (I think) a linker problem where it finds two things where it should only find one and cannot resolve the discprency. I'd appreciate it if anyone can tell me if I'm correct here. Thanks.
2)WHat does the "C" part do? The author states that this "exports the functions in plain C-style without C++ name mangling" - "The overhead of object orientation forces C++ to twist around the function names and parameter lists a bit, but we don't want to worry about that and so we enforce plain C usage of those functions here". WHAT? So is he suggesting that there is some inherent flaw within C++ and C++ compilers that makes the basic functional modus operandi of the language useless without clever tricks and hacks? I don't think so somehow. SO what is he trying to achieve here? And what does any of that mean?
3)
typedef HRESULT (*CREATERENDERDEVICE) (HINSTANCE hDLL, ZFXRenderDevice** pInterface);I don't understand this line? What is he typedef'ing here? I don't understand what the subject of the typedef is. Is it the function pointer or the argument list or what? Is somehow just doesn't look like a typical typedef statement to me.That's it for now. ANy help anyone can offer would be appreicated cheers! :oD